I'm trying to do all my image processing in the GPU and not cpu processing:

# coding=utf8
import cv2

# Leer la imagen en la GPU
image = cv2.cuda_GpuMat()
image.upload(cv2.imread("sutil.jpeg"))
original = image


# Convertir la imagen de BGR a HSV en la GPU
image = cv2.cuda.cvtColor(image, cv2.COLOR_BGR2HSV)

# Convertir la imagen a escala de grises en la GPU
image = cv2.cuda.cvtColor(image, cv2.COLOR_BGR2GRAY)


# Binarizar la imagen en escala de grises con el método de Otsu en la GPU
ret, otsu = cv2.cuda.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

# Aplicar una máscara binaria a la imagen original del limón en la GPU
result = cv2.cuda.bitwise_and(original, original, mask=otsu)

# Mostrar la imagen resultante segmentada
cv2.imshow('Imágen Resultante Segmentada',image)
cv2.waitKey(0)

enter image description here

However after apply the HSV conversion, the next step is apply otsu thresholding, and it is throwing this error:

Traceback (most recent call last):
  File "gpu.py", line 18, in <module>
    ret, otsu = cv2.cuda.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.error: OpenCV(4.5.4) /home/orin/opencv_contrib/modules/cudaarithm/src/cuda/threshold.cu:105: error: (-215:Assertion failed) type <= 4 in function 'threshold'

what does mean it "type <= 4 in function 'threshold'" I don't know why this happens, my code on cpu works perfectly:

import cv2

image = cv2.imread("sutil.jpeg")
original = image

image = cv2.blur(image,(31,31),0)

# Convert BGR a HSV para saturar la imágen.

image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

#convertir a escala de grises (CV_RGB2GRAY)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#Binarizar la imagen en escala de grises con el método de Otsu.
ret, otsu = cv2.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

#Aplicar mascara binaria a la imagen original del limón.
result = cv2.bitwise_and(original, original, mask=otsu)

cv2.imshow('Imagen Resultante Segmentada', result)
cv2.waitKey(0)

also a detail in my gpu code version is that I removed "cv2.blur(image,(31,31),0)" because I can't do it, if you any idea guys to fix this two problems I will appreciate it.

thanks so much.

1

There are 1 answers

3
Christoph Rackwitz On

Documentation states:

The THRESH_OTSU and THRESH_TRIANGLE threshold types are not supported.