C ++ / openCV:无法打开相机

时间:2014-06-13 09:40:29

标签: c++ linux opencv beagleboneblack

我尝试在Beaglebone Black上使用openCV从USB摄像头捕获单帧。

首先我的设置:
我有一个带有Qt的Debian 7 VM来交叉编译 我正在使用Qt 5.2
在Beaglebone上我也运行Debian 7 我在VM和BBB(http://aplacetogeek.wordpress.com/qt-opencv-v4l-cross-compiling-raspberry-pi-beagle-bone/

中构建了openCV 2.4.1和2.4.9

如果我在VM中编译,我可以捕获图片。如果我为BBB编译它无法打开相机设备。

这里的方法(仅用于测试,我知道它是非常的^^):

cv::VideoCapture * cam0 = new cv::VideoCapture(0);

if (cam0->isOpened())
{
    cam0->set(CV_CAP_PROP_FRAME_WIDTH, 1280);
    cam0->set(CV_CAP_PROP_FRAME_HEIGHT, 720);
    cam0->set(CV_CAP_PROP_FOURCC, CV_FOURCC('M','J','P','G'));
    cam0->set(CV_CAP_PROP_FPS, 5);
}
else
{
    qDebug()<<"Could not open cam0";
    delete cam0;
    cam0 = NULL;
}

cv::VideoCapture * cam1 = new cv::VideoCapture(1);
if (cam1->isOpened())
{
    cam1->set(CV_CAP_PROP_FRAME_WIDTH, 1280);
    cam1->set(CV_CAP_PROP_FRAME_HEIGHT, 720);
    cam1->set(CV_CAP_PROP_FOURCC, CV_FOURCC('M','J','P','G'));
    cam1->set(CV_CAP_PROP_FPS, 5);
}
else
{
    qDebug()<<"Could not open cam1";
    delete cam1;
    cam1 = NULL;
}

qDebug()<<"Here I am! :)";

if ((cam0 != NULL) || (cam1 != NULL))
{
    cv::Mat frame;
    for (int i=0;i<10;i++)
    {
        QString num;
        num = QString::number(i);

        if (cam0 != NULL)
        {
            cam0->grab();
            if (cam0->retrieve(frame))
            {
                QString vm0("/home/administrator/Bilder/0captured_yay"+num+".jpg");
                QString bbb0("/home/debian/pics/0captured_yay"+num+".jpg");

                qDebug()<<"Write "<<bbb0;
                cv::imwrite(vm0.toStdString(), frame);
                cv::imwrite(bbb0.toStdString(), frame);
            }
            else
                qDebug()<<"cam0: Could not grab frame "<<i+1;
        }

        if (cam1 != NULL)
        {
            cam1->grab();
            if (cam1->retrieve(frame))
            {
                QString vm1("/home/administrator/Bilder/1captured_yay"+num+".jpg");
                QString bbb1("/home/debian/pics/1captured_yay"+num+".jpg");

                qDebug()<<"Write "<<bbb1;
                cv::imwrite(vm1.toStdString(), frame);
                cv::imwrite(bbb1.toStdString(), frame);
            }
            else
                qDebug()<<"cam1: Could not grab frame "<<i+1;
        }

        this->thread()->sleep(1);
    }
}

在VM中,它可以很好地写入图片。但是在BBB上我得到了输出:

Could not open cam0 
Could not open cam1 
Here I am! :) 
Here I go... :( 

0 个答案:

没有答案