# Trying to call \`cv.cuda.warpAffine\`

**URL:** <https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124>\
**Category:** Python\
**Tags:** cuda\
**Created:** [August 3, 2023, 9:40pm UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124 "2023-08-03T21:40:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_Sjogren](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joel_sjogren/32/8441_2.png) [@Joel\_Sjogren](https://forum.opencv.org/u/Joel_Sjogren)\
**Post date:** [August 3, 2023, 9:40pm UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124/1 "2023-08-03T21:40:10Z")

</div>

```auto
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!

---

<div class="post-metadata">

**Author:** ![Joel\_Sjogren](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joel_sjogren/32/8441_2.png) [@Joel\_Sjogren](https://forum.opencv.org/u/Joel_Sjogren)\
**Post date:** [August 3, 2023, 10:14pm UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124/2 "2023-08-03T22:14:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joel\_Sjogren](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joel_sjogren/32/8441_2.png) [@Joel\_Sjogren](https://forum.opencv.org/u/Joel_Sjogren)\
**Post date:** [August 5, 2023, 11:44am UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124/4 "2023-08-05T11:44:39Z")

</div>

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! 😃

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 5, 2023, 2:07pm UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124/6 "2023-08-05T14:07:53Z")

</div>

_Notice_: Dima\_Fantasy was an AI spam bot. do not trust anything the AI spam bot posted.

---

<div class="post-metadata">

**Author:** ![Joel\_Sjogren](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joel_sjogren/32/8441_2.png) [@Joel\_Sjogren](https://forum.opencv.org/u/Joel_Sjogren)\
**Post date:** [August 5, 2023, 2:10pm UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124/7 "2023-08-05T14:10:33Z")

</div>

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! 😛

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [August 6, 2023, 5:13am UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124/8 "2023-08-06T05:13:32Z")

</div>

> [@Joel\_Sjogren](#):
>
> It just freezes!

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

> [@Joel\_Sjogren](#):
>
> `cv.cuda.warpAffine(gpu_img, np.array([[1, 0, 0], [0, 1, 0]]), (10, 10), dst=gpu_rot)`

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

```auto
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

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

```

---

<div class="post-metadata">

**Author:** ![Joel\_Sjogren](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joel_sjogren/32/8441_2.png) [@Joel\_Sjogren](https://forum.opencv.org/u/Joel_Sjogren)\
**Post date:** [August 6, 2023, 8:55am UTC](https://forum.opencv.org/t/trying-to-call-cv-cuda-warpaffine/14124/9 "2023-08-06T08:55:54Z")

</div>

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