ndimage.Rotate用于旋转现场视频的旋转使其非常慢(Python)

发布于 2025-01-24 20:16:34 字数 874 浏览 1 评论 0原文

我的目的是让网络摄像头传输实时饲料,我可以通过一些降级来旋转图像馈电(该部分将由陀螺仪的值控制)。问题是,尽管使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文