【发布时间】:2020-01-21 17:07:46
【问题描述】:
我编写了一个 python 脚本(使用 OpenCV)来启动,从我的网络摄像头捕获视频,将其转换为灰度并显示以下视频。当我第一次编译它时,它工作得很好,但在第三或第四次编译之后,它被困在只捕获网络摄像头启动时的第一帧。 这是代码:
import numpy
import cv2 as cv
cap=cv.VideoCapture(0)
while(True):
#capture frame by frame
ret, frame = cap.read() #cv.VideoCapture(0) aslo returns a boolean true value if read correctly
#Operations on the frame
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
#display
cv.imshow('frame', gray)
if cv.waitKey(0) &0xFF: #== ord('q'):
break
#when everything is done, realse the capture
cap.realse()
cv.destroyAllWindows()
【问题讨论】:
标签: python visual-studio opencv visual-studio-code