使用树莓派上的 opencv4 videocapture 对象在 read() 2 次后冻结。
细节:
- Raspberrypi Jessie
- python 2.7 + opencv 4
- python code can be run on windows10 (py2.7 and opencv4) without problem
这是基于示例的代码:
import cv2
ret, frame = cap.read()
cap = cv2.VideoCapture(0)
countDown = 20
while(countDown > 0 ):
ret, frame = cap.read()
print countDown , "readed"
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# cv2.imwrite ( "test" + str(countDown) + ".png" , gray )
if cv2.waitKey(1) & 0xFF == ord('q'):
break
countDown -= 1
cap.release()
结果 :
20 readed
19 readed
then hangs forever........