Trying to call `cv.cuda.warpAffine`

box% python
Python 3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np, cv2 as cv
>>> gpu_img = cv.cuda.GpuMat()
>>> gpu_img.upload(np.array([[1,2,3,4,5,6],[1,5,3,2,1,4]]))
>>> gpu_rot = cv.cuda.GpuMat()
>>> cv.cuda.warpAffine(gpu_img, np.array([[1, 0, 0], [0, 1, 0]]), (10, 10), dst=gpu_rot)

It just freezes!

Switched to using GitHub - Fizmath/Docker-opencv-GPU: GPU-accelerated Docker container with OpenCV 4.5, Python 3.8 , GStreamer and CUDA 10,2 for now. It works.

Blocking Operation - not a reasonable interpretation since it blocks very long
Incorrect Transformation Matrix - the identity matrix is a valid transformation matrix, and anyways it is not possible to visualize the result if there is no result, due to non-termination
Resource Allocation - in principle yes, however the docker version works

Check for Errors - there are none since it freezes, it doesn’t terminate
Use a Non-GPU Version - sure that works, as well as the docker GPU version as stated above
Check Resource Usage - nvidia-smi showed the GPU was not under load
Try Different Transformation - n/a as argued above

gtx 1080, arch package nvidia 535.86.05-8, no error messages due to freezing (can’t even Ctrl+C to provoke any error messages, it’s completely stuck)

Thank you for your suggestions. Personally I believe the most likely explanation is some sort of linking error, something about versions not matching up, but this is just my guess and I don’t know how to investigate it. Anyways, I am not in urgent need of a solution anymore since I found the prebuilt docker image as an alternative, and I have almost finished my CV project already! :smiley:

Notice: Dima_Fantasy was an AI spam bot. do not trust anything the AI spam bot posted.

Yeah, especially the second reply felt eerily similar to chatgpt in its politeness and sequential agreement with the things that I wrote. And in retrospect the first reply was similar to the kind of list of options that I have received from chatgpt when playing around with it. Thanks for notifying me! :stuck_out_tongue:

It doesn’t freeze for me, which version of OpenCV and CUDA are you using?

If you want to call with dst you need to initialize gpu_rot to the correct size and type first, i.e.

gpu_rot = cv.cuda.GpuMat(10,10,gpu_img.type())

otherwise due to the way the python bindings are implemented dst won’t get populated. Alternatively for a one off when experimenting you can call it without the dst parameter and allow cv.cuda.warpAffine to allocate a new GpuMat on every invocation as

gpu_rot = cv.cuda.warpAffine(gpu_img, np.array([[1, 0, 0], [0, 1, 0]]), (10, 10))

Thank you, I get almost 3x speedup by preallocating.

1 Like