Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用OpenCV获取BeagleBone捕捉静止帧_Linux_Opencv_Beagleboard_Angstrom Linux_Video4linux - Fatal编程技术网

Linux 使用OpenCV获取BeagleBone捕捉静止帧

Linux 使用OpenCV获取BeagleBone捕捉静止帧,linux,opencv,beagleboard,angstrom-linux,video4linux,Linux,Opencv,Beagleboard,Angstrom Linux,Video4linux,我有一个BeagleBone运行3.2.28,我正试图从我的相机中捕捉一帧 因此,我插入我的USB网络摄像头,并检查/dev以确保它显示出来 它是这样的,正如video0(右下角)。我知道这是正确的,因为在我拔掉相机插头后它就消失了 现在我启动Python并运行以下程序: root@beaglebone:/dev# python Python 2.7.2 (default, Sep 11 2012, 16:15:43) [GCC 4.5.4 20120305 (prerelease)] on

我有一个BeagleBone运行3.2.28,我正试图从我的相机中捕捉一帧

因此,我插入我的USB网络摄像头,并检查
/dev
以确保它显示出来

它是这样的,正如
video0
(右下角)。我知道这是正确的,因为在我拔掉相机插头后它就消失了

现在我启动Python并运行以下程序:

root@beaglebone:/dev# python
Python 2.7.2 (default, Sep 11 2012, 16:15:43)
[GCC 4.5.4 20120305 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
>>> capture=cv.CaptureFromCAM(-1)
>>> img=cv.QueryFrame(capture)
>>> type(capture)
<type 'cv2.Capture'>
>>> type(img)
<type 'NoneType'>
你可以看到,在这里我确实捕捉到了一幅图像。我不知道接下来该怎么办

更新:

我已经玩了一些,并且能够通过发出以下命令让相机响应(即,它的灯亮起):

root@beaglebone:/# ffmpeg -f video4linux2 -i /dev/video0

这很有趣,因为
CaptureFromCAM
使用V4L接口。。。我不知道从这里走到哪里。

我不确定这是否是一个答案。请尝试以下方法

我猜,摄像头驱动程序不受支持。将摄像头连接到电路板上,并在终端中键入“dmesg”,查看是否检测到摄像头制造商名称

如果消息中没有制造商名称,则应从终端安装摄像头驱动程序:

opkg update
opkg install kernel-module-uvcvideo
modprobe uvcvideo
如果上述步骤对您没有帮助,请尝试安装或安装任何其他支持摄像头视频输入的播放器,然后尝试是否正常工作。:)

最重要的是确保
CaptureFromCAM()
成功

import cv
capture = cv.CaptureFromCAM(-1)
if not capture:
    print "Unable to open device #-1"
    sys.exit(1) 
-1
作为参数发送,告诉OpenCV打开默认的相机设备。在某些系统上,这不起作用,您需要增加该数字。尝试传递
0
,然后传递
1
,再传递
2

您需要做的第二件事是确保
QueryFrame()
也返回有效的内容:

img = cv.QueryFrame(capture)
if not img:
    print "Unable to retrieve frame from the device"
    sys.exit(1) 
我见过OpenCV的Python API和C(甚至C++)API之间的奇怪行为。如果以上这些都不能解决问题,我建议您使用OpenCV编译一个C程序(它具有最可靠的API)从相机检索数据。在某些情况下,OpenCV的C API可以工作,而Python不能

从相机检索帧并将其显示在窗口中:

#include <stdio.h>
#include <highgui.h>
#include <cv.h>

int main() 
{
CvCapture* capture = NULL;
if ((capture = cvCaptureFromCAM(-1)) == NULL)
{
    fprintf(stderr, "ERROR: capture is NULL \n"); 
    return -1;
}

cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);

cvQueryFrame(capture); // Sometimes needed to get correct data

while (1) 
{     
    IplImage* frame = cvQueryFrame(capture); // check return
    {
        fprintf( stderr, "ERROR: cvQueryFrame failed\n");
        break;
    }

    // At this point you already have the frame! There's no need to
    // repeat the thing 10x with cvGrabFrame and cvRetrieveFrame. 
    // You are probably sabotaging yourself doing this multiple times.

    cvShowImage("mywindow", frame); // Do not release the frame!

    int key = cvWaitKey(10);
    if (key  == 0x1b)
        break;
}    

cvReleaseCapture(&capture);   
cvDestroyWindow("mywindow");   

return 0;
}
#包括
#包括
#包括
int main()
{
CvCapture*capture=NULL;
if((capture=cvCaptureFromCAM(-1))==NULL)
{
fprintf(stderr,“错误:捕获为空\n”);
返回-1;
}
cvNamedWindow(“mywindow”,CV_WINDOW_AUTOSIZE);
cvQueryFrame(capture);//有时需要获取正确的数据
而(1)
{     
IplImage*frame=cvQueryFrame(捕获);//检查返回
{
fprintf(stderr,“错误:cvQueryFrame失败\n”);
打破
}
//在这一点上你已经有了框架!没有必要
//用cvGrabFrame和cvRetrieveFrame重复10次。
//你可能多次这样做都在破坏自己。
cvShowImage(“mywindow”,框架);//不要释放框架!
int key=cvWaitKey(10);
如果(键==0x1b)
打破
}    
cvReleaseCapture(&capture);
CvWindow(“mywindow”);
返回0;
}
  • 尝试使用任何V4L2应用程序,并尝试在不使用任何代码的情况下测试相机。有Qt V4L2软件,您可以下载并测试相机
  • 如果第一步失败,则说明您的相机驱动程序存在问题,并且不支持
  • 如果第一步成功,请检查您的代码并尝试使用gstreamer或任何现成的V4L2捕获示例

  • 我遇到了摄像头可以识别的问题,但是驱动程序有bug,所以首先检查一下您的内核是否真的支持摄像头的驱动程序。提到你的相机型号也很好。它是什么样的接口,还是USB?我怀疑这是驾驶员的问题。

    是的,摄像头会响应。一些相机型号在拍摄图像时会闪烁LED灯。你有没有试过做这样的事情。还有,保存图像怎么样?啊,它没有响应。。。这是更多的信息,但仍然不确定去哪里?我对linux相当陌生。我知道相机工作正常(至少在我的windows机器上)。我按照您的指示安装了uvcvideo模块,但仍然无法工作。。。任何其他建议(我仍在挖掘期间),所以我运行
    modprobe uvcvideo
    后是否应该看到任何具体的建议?您必须看到类似的内容:视频捕获接口:v2.00;注册新接口驱动程序uvcvideo;视频类驱动程序(1.1.1)这将确保驱动程序安装正确。连接摄像头时,应打印cam in终端的型号详细信息。如果没有,请执行“dmesg”并查看最后几行是否显示:usb 1-2.1:产品:网络摄像头C110让我们不要通过从头开始搜索问题来将事情复杂化。向我展示“modprobe uvcvideo”和“dmesg”的输出可能会为我们提供一些解决问题的线索。您编写的python代码与我执行的步骤相同,我返回相同的结果。尝试编译链接到的C代码(注意:我不知道任何C)返回(注意,我将文件命名为temp.C)。。。。。。。温度c:1:10:错误:应为“=”,“,”,“;”,”“*”之前的asm”或“attribute”表示抱歉,该代码缺少
    main()
    函数。我在回答中加入了完整的应用程序。如果您还有任何编译问题,请告诉我。
    #include <stdio.h>
    #include <highgui.h>
    #include <cv.h>
    
    int main() 
    {
    CvCapture* capture = NULL;
    if ((capture = cvCaptureFromCAM(-1)) == NULL)
    {
        fprintf(stderr, "ERROR: capture is NULL \n"); 
        return -1;
    }
    
    cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
    
    cvQueryFrame(capture); // Sometimes needed to get correct data
    
    while (1) 
    {     
        IplImage* frame = cvQueryFrame(capture); // check return
        {
            fprintf( stderr, "ERROR: cvQueryFrame failed\n");
            break;
        }
    
        // At this point you already have the frame! There's no need to
        // repeat the thing 10x with cvGrabFrame and cvRetrieveFrame. 
        // You are probably sabotaging yourself doing this multiple times.
    
        cvShowImage("mywindow", frame); // Do not release the frame!
    
        int key = cvWaitKey(10);
        if (key  == 0x1b)
            break;
    }    
    
    cvReleaseCapture(&capture);   
    cvDestroyWindow("mywindow");   
    
    return 0;
    }