ndimage.Rotate用于旋转现场视频的旋转使其非常慢(Python)
我的目的是让网络摄像头传输实时饲料,我可以通过一些降级来旋转图像馈电(该部分将由陀螺仪的值控制)。问题是,尽管使用ndimage.Rotate以正确的角度旋转,但视频变得非常缓慢(低于10 fps)。这是im使用它的示例代码(在这里我使用固定角度来演示):
import cv2
from scipy import ndimage
cap = cv2.VideoCapture(0)
mode=2 #mode 1 = Normal mode, mode 2 = Rotated mode
# Check if the webcam is opened correctly
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=1, fy=1, interpolation=cv2.INTER_AREA)
if mode==1:
cv2.imshow('Input', frame) #Original version
else:
rotate=ndimage.rotate(frame, angle=45, reshape=False)
cv2.imshow('Input', rotate) #Rotated version (very slow)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
如何使视频与原始模式一样快地运行?或至少更快。
谢谢,这是我的第一个问题,所以我很抱歉我错过了什么。
My objective is to have the webcam transmitting live feed and I could rotate the image feed by some degries (this part would be controlled by the values of a gyroscope). The problem is although the image rotates when using ndimage.rotate by the correct angle the video becomes really slow (below 10 fps). This is an example code of how im using it (in here I use a fixed angle just to demonstrate):
import cv2
from scipy import ndimage
cap = cv2.VideoCapture(0)
mode=2 #mode 1 = Normal mode, mode 2 = Rotated mode
# Check if the webcam is opened correctly
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=1, fy=1, interpolation=cv2.INTER_AREA)
if mode==1:
cv2.imshow('Input', frame) #Original version
else:
rotate=ndimage.rotate(frame, angle=45, reshape=False)
cv2.imshow('Input', rotate) #Rotated version (very slow)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
How can I make the video to run as fast as the original mode? Or at least somewhat faster.
Thanks, its my first question so I apologize if Im missing something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论