opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

CUDA GpuMat ConvertTo() error

Open ccarmatic opened this issue 1 year ago • 1 comments

Expected behaviour

I am using CUDA

I have a Numpy array in np.float16 format, from a greyscale image, with dimensions of HEIGHT and WIDTH I am trying to scale it with ConvertTo and output it in 8 bit unsigned integer

16fnumpyarray = inputarray.astype(np.float16)
myGpuMat= cv2.cuda.GpuMat(HEIGHT,WIDTH,cv2.CV_16F)
TargetGpuMat= cv2.cuda.GpuMat(HEIGHT,WIDTH,cv2.CV_8U)
scaling = np.random.default_rng()

myGpuMat.upload(16fnumpyarray)

myGpuMat.convertTo(cv2.CV_8U,alpha=scaling,beta=1,dst=TargetGpuMat)

expected behaviour is returning TargetGpuMat successfully

Actual behaviour

actual behaviour is an error code: cv2.error: Unknown C++ exception from OpenCV code

Steps to reproduce

  • example code : provided above

  • operating system : latest Windows 11

  • architecture : x64

  • opencv-python version : Cudawarped 4.10.0.84 version

  • [ ] The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")

  • [ ] I'm using the latest version of opencv-python

ccarmatic avatar Sep 30 '24 18:09 ccarmatic

Solved by using fp32 instead of fp16, it looks like this function is not compatible with fp16

ccarmatic avatar Sep 30 '24 19:09 ccarmatic

Alternative solution: convertFp16(): https://docs.opencv.org/4.x/d8/d40/group__cudacore__init.html#gaa1c52258763197958eb9e6681917f723

asmorkalov avatar Jan 15 '25 13:01 asmorkalov