简体   繁体   English

访问Beaglebone python opencv usb摄像头,但显示屏显示黑屏

[英]Accessing Beaglebone python opencv usb camera but the display showing black screen

I am facing issue while accessing USB camera using beagle-bone black wireless. 使用beagle-bone黑色无线访问USB摄像头时遇到问题。 Firstly the error is "select timeout" exception which was resolved by this post 首先错误是“选择超时”除外,它被解决了这个帖子

Now I am facing the black screen in output. 现在我面对输出中的黑屏。

Here is the testing code I am using. 这是我正在使用的测试代码。

from cv2 import *
# initialize the camera
cam = VideoCapture(0)   # 0 -> index of camera
print "Cam capture"
cam.set(3,320)
cam.set(4,240)
print "Cam set"
s, img = cam.read()
print "Cam read"
if s:    # frame captured without any errors
    namedWindow("cam-test",CV_WINDOW_AUTOSIZE)
    imshow("cam-test",img)
    while True:
        key = waitKey(30)
        if key == ord('q') :
                destroyWindow("cam-test")

I have already check that video0 in /dev directory. 我已经检查了/ dev目录中的video0。

The issue is that you need to call 'cam.read() and imshow()` inside the while loop 问题是您需要在while循环中调用'cam.read() and imshow()`。

What you're doing is that you're reading just the first frame, then showing it, and you while loop isn't doing anything. 您正在做的是先阅读第一帧,然后显示它,而while循环却什么也没做。 When the camera boots, the first frame is just a blank screen , which is what you see. 相机启动时,第一帧只是空白屏幕,这就是您所看到的。

The code should be more like: 该代码应该更像:

    while True:
        s, img = cam.read()
        imshow("cam-test",img)
        key = waitKey(30)
        if key == ord('q') :
                destroyWindow("cam-test")

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

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