Home > Net >  Use opencv in python with gpu support to rotate images
Use opencv in python with gpu support to rotate images

Time:12-17

I have compiled opencv 4.6.0 from source files with the cuda support. I have followed the guide for windows 10

The process is completed and I can see my gpu. I want to rotate an image by using GPU. In other words I have this simple code

import cv2
img = cv2.imread("cat.3.jpg")
a = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
cv2.imshow("cat", a)
cv2.waitKey(0)

It works fine, but on CPU. I want a similar code in Python that runs on GPU. A similar solution presented here for C .

CodePudding user response:

I have found the solution. This is the code that I have developed

import cv2
import cv2.cuda as cuda
image = cv2.imread("myimage.jpg")

# Storing the image on GPU
src = cv2.cuda_GpuMat()
src.upload(image)

# Applying the rotation
a = cv2.cuda.rotate(src=src, dsize = (414,500), angle = 12, xShift= 0, yShift=0, interpolation=cv2.INTER_NEAREST)

# Downloading the image from GPU and visualizing the image
result = a.download()
cv2.imshow("cat", result)
cv2.waitKey(0)
  • Related