第二次在openCV中不能使用VideoCapture

时间:2014-12-13 16:46:45

标签: python-2.7 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()

我做错了什么?

0 个答案:

没有答案