简体   繁体   English

在支持 gpu 的 python 中使用 opencv 来旋转图像

[英]Use opencv in python with gpu support to rotate images

I have compiled opencv 4.6.0 from source files with the cuda support.我已经使用 cuda 支持从源文件编译了 opencv 4.6.0。 I have followed the guide for windows 10我已遵循 Windows 10 指南

The process is completed and I can see my gpu.该过程已完成,我可以看到我的 gpu。 I want to rotate an image by using GPU.我想使用 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.它工作正常,但在 CPU 上。 I want a similar code in Python that runs on GPU.我想要在 GPU 上运行的 Python 中的类似代码。 A similar solution presented here for C++. 此处为 C++ 提供了类似的解决方案。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM