无法在树莓派上打开相机 - VIDIOC_STREAMON:无效参数和 VIDIOC_DQBUF

发布于 2025-01-11 04:00:37 字数 1033 浏览 0 评论 0原文

我有以下 python 脚本来处理相机输入

if __name__ == '__main__':
def run_vc():
cap = cv2.VideoCapture(0)


if cap is None or not cap.isOpened():
    print("Error opening video")
    cap.release()
    cv2.destroyAllWindows()

signal.signal(signal.SIGTERM, signal_term_handler)

try:
    while True:
        retval, img = cap.read()
        .... # do some stuff
    
    # free camera object and exit
    print("app finish")
    cap.release()
    cv2.destroyAllWindows()

except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
    print("Keyboard interrupt")
    cap.release()
    cv2.destroyAllWindows()

except ValueError:
    print("some error" + str(ValueError))
    cap.release()
    cv2.destroyAllWindows()

def signal_term_handler(sigNum, frame):
    # on receiving a signal initiate a normal exit
    raise SystemExit('terminating')

if __name__ == '__main__':
    run_vc()

如果树莓派意外关闭并且我尝试再次运行代码我会收到以下错误

VIDIOC_STREAMON: Invalid argument

所以可能有一些句柄或资源需要释放。 有人可以帮忙吗?

I have the following python script to handle camera input

if __name__ == '__main__':
def run_vc():
cap = cv2.VideoCapture(0)


if cap is None or not cap.isOpened():
    print("Error opening video")
    cap.release()
    cv2.destroyAllWindows()

signal.signal(signal.SIGTERM, signal_term_handler)

try:
    while True:
        retval, img = cap.read()
        .... # do some stuff
    
    # free camera object and exit
    print("app finish")
    cap.release()
    cv2.destroyAllWindows()

except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
    print("Keyboard interrupt")
    cap.release()
    cv2.destroyAllWindows()

except ValueError:
    print("some error" + str(ValueError))
    cap.release()
    cv2.destroyAllWindows()

def signal_term_handler(sigNum, frame):
    # on receiving a signal initiate a normal exit
    raise SystemExit('terminating')

if __name__ == '__main__':
    run_vc()

And if the raspberry shutdown unexpectedly and I try to run the code once again I get following error

VIDIOC_STREAMON: Invalid argument

So there are maybe some handles or resources to be freed.
Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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