简体   繁体   English

为什么网络摄像机无法以python代码读取视频供稿?

[英]Why isn't the video feed read by the web camera in python code?

When I run my python opencv code, the web camera does not read a video feed. 当我运行python opencv代码时,网络摄像头不会读取视频供稿。 There are no any errors, but the black color output with wifi sign and loading sign i there. 没有任何错误,但黑色输出带有wifi信号和加载信号i。 How to fix that and read the video feed. 如何解决该问题并阅读视频供稿。 Here is my code and the output. 这是我的代码和输出。

import cv2

cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))

print(cap.isOpened())
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
       print(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
       print(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

       out.write(frame)

       gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
       cv2.imshow('frame', gray)

       if cv2.waitKey(1) & 0xFF == ord('q'):
         break
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

在此处输入图片说明

If you are only using one camera you can try the following: 如果您仅使用一台摄像机,则可以尝试以下操作:

cap = cv2.VideoCapture(-1)

This will pick up the first webcam the system can find. 这将获取系统可以找到的第一个网络摄像头。 How are you overlaying the wifi/loading signs - I assume they are not part of the webcam feed? 您如何覆盖wifi /加载标志-我假设它们不属于网络摄像头供稿?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM