我已经在python中使用opencv尝试了视频捕获程序。代码在下面给出
from cv2 import *
a=VideoCapture(0)
while(True):
b,c=a.read()
imshow("video",c)
if(waitKey()==ord('s')):
break
a.release()
destroyAllWindows()
对于上面的代码,我的网络摄像头正在打开。但是该视频无法播放,我尝试了很多视频,但仍显示为图像。我该如何播放视频。有人可以提供解决方案吗?
>答案 0 :(得分:2)
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
答案 1 :(得分:0)
您的if条件存在问题。正确的方法是这样
import cv2 as cv
a = cv.VideoCapture(0)
while True:
b, c = a.read()
cv.imshow("video", c)
if cv.waitKey(1) & 0xFF == ord("q"):
break
a.release()
cv.destroyAllWindows()