繁体   English   中英

代码检测到网络摄像头时,cv2模块未捕获图像

[英]cv2 module is not capturing the image while the code is detecting the webcam

我使用的代码是:

import cv2

camera = cv2.VideoCapture(0)
im=camera.read()[1]
print im

对于我正在输出为
在某些情况下,它会返回RGB值,但并非每次都返回。
在这种情况下,它将返回None?

您的问题是:

在这种情况下,它将返回None?

这可以在VideoCapture的文档中轻松找到。 对于该功能,请阅读以下内容:

方法/函数在一次调用中组合了VideoCapture :: grab()和VideoCapture :: retrieve()。 这是读取视频文件或从解码中捕获数据并返回刚抓取的帧的最方便的方法。 如果没有抓取帧 (相机已断开连接,或者视频文件中没有其他帧), 则方法返回false,函数返回NULL指针。

因此,与相机的连接似乎是问题所在。

import cv2

cv2.namedWindow('webCam')

cap = cv2.VideoCapture(0)


if cap.isOpened():
    ret, frame = cap.read()
else:
    ret = False
    print "problem here"


while True:
    #get frames
    ret,frame = cap.read()
    frame = cv2.flip(frame,1)  # flip image 

    cv2.imshow('webCam', frame)  # show cam

    # to exit
    esc = cv2.waitKey(5) & 0xFF == 27
    if esc:
        break

cap.release()
cv2.destroyAllWindows()

暂无
暂无

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

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