python – 如何使用OpenCV从网络摄像头读取视频?
我正在关注
the official documentation,尝试从网络摄像头中读取视频.当我从文档中运行一段代码时:
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() 它失败并带有以下输出:
进一步检查,似乎: > ret永远是假的. 在VLC中打开/ dev / video0显示来自网络摄像头的视频.当我打开Cheese时,它还会显示来自网络摄像头的视频.只有一台摄像机连接到PC. 有什么建议? 解决方法
你可能错过了FFMPEG. OpenCV需要编解码器信息来解码ffmpeg提供的视频,打开相机等.
在Windows上安装FFmpeg的步骤在此处详细说明http://www.wikihow.com/Install-FFmpeg-on-Windows.遵循Linux相当于此可能会解决您的问题 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |