-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliper.py
More file actions
38 lines (32 loc) · 1.46 KB
/
cliper.py
File metadata and controls
38 lines (32 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import cv2
# Verifica se o OpenCV tem suporte a CUDA
print("OpenCV foi compilado com suporte a CUDA?", 'YES' if cv2.cuda.getCudaEnabledDeviceCount() > 0 else 'NO')
# Se houver dispositivos CUDA disponíveis
if cv2.cuda.getCudaEnabledDeviceCount() > 0:
# Exibe informações sobre o(s) dispositivo(s) CUDA
for i in range(cv2.cuda.getCudaEnabledDeviceCount()):
print(f"\nInformações do dispositivo CUDA {i}:")
prop = cv2.cuda.getDeviceProperties(i)
print(f"Nome: {prop.name}")
print(f"Multiprocessadores: {prop.multiProcessorCount}")
print(f"Clock rate: {prop.clockRate}")
print(f"Memória total: {prop.totalGlobalMem / (1024 ** 3):.2f} GB")
# Teste básico com GPU: carregar imagem e aplicar Canny Edge Detection na GPU
img = cv2.imread('test_image.jpg') # Substitua por um caminho válido
if img is None:
print("Erro ao carregar a imagem. Coloque uma imagem chamada 'test_image.jpg' no diretório.")
else:
# Envia a imagem para a GPU
gpu_img = cv2.cuda_GpuMat()
gpu_img.upload(img)
# Aplica detecção de bordas Canny na GPU
edges_gpu = cv2.cuda.Canny(gpu_img, 100, 200)
# Baixa o resultado para CPU e mostra
edges = edges_gpu.download()
# Mostra as imagens
cv2.imshow('Original', img)
cv2.imshow('Edges (GPU)', edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print("Nenhum dispositivo CUDA disponível.")