无法在树莓派上打开相机 - VIDIOC_STREAMON:无效参数和 VIDIOC_DQBUF
我有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论