我正在使用树莓派捕捉视频的前 20 帧。现在这更像是一个概念问题,但是在浏览 videoCapture 上的 openCV 文档时,他们强调了在此代码中发布捕获的重要性(如他们网站上发布的那样):
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
cap.release()
的重要性是什么?忽略这一行是否对记忆有影响?如果有,它们是什么,为什么?
原文由 Veejay 发布,翻译遵循 CC BY-SA 4.0 许可协议
当您致电
cap.release()
时,则:您可以在调用
cap2 = cv2.VideoCapture(0)
cap.release()
。因为你还没有释放相机设备资源,那么它会引发类似
Device or resource busy
的错误,导致引发 OpenCV 异常。