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
OPENCV 3.1 videoio错误:v4l:设备/dev/video无法查询频道数 我在运行Ubuntu 12.04的工作站上有一个用OpenCV 3.1编写的C++程序。该程序每5分钟从USB摄像头(/dev/video2)捕获一帧,执行一些操作,并将帧保存到磁盘。出于某种原因,程序抛出了这个运行时错误,但代码似乎工作得很好,也就是说,它正在捕获和保存帧,即使运行了几天……我只是想知道运行时错误是什么意思,为什么抛出,我是否需要担心它? VIDEOIO错误:V4L:设备/dev/video2:无法查询频道数_C++_Opencv_Ubuntu 12.04_Opencv3.1_V4l - Fatal编程技术网

OPENCV 3.1 videoio错误:v4l:设备/dev/video无法查询频道数 我在运行Ubuntu 12.04的工作站上有一个用OpenCV 3.1编写的C++程序。该程序每5分钟从USB摄像头(/dev/video2)捕获一帧,执行一些操作,并将帧保存到磁盘。出于某种原因,程序抛出了这个运行时错误,但代码似乎工作得很好,也就是说,它正在捕获和保存帧,即使运行了几天……我只是想知道运行时错误是什么意思,为什么抛出,我是否需要担心它? VIDEOIO错误:V4L:设备/dev/video2:无法查询频道数

OPENCV 3.1 videoio错误:v4l:设备/dev/video无法查询频道数 我在运行Ubuntu 12.04的工作站上有一个用OpenCV 3.1编写的C++程序。该程序每5分钟从USB摄像头(/dev/video2)捕获一帧,执行一些操作,并将帧保存到磁盘。出于某种原因,程序抛出了这个运行时错误,但代码似乎工作得很好,也就是说,它正在捕获和保存帧,即使运行了几天……我只是想知道运行时错误是什么意思,为什么抛出,我是否需要担心它? VIDEOIO错误:V4L:设备/dev/video2:无法查询频道数,c++,opencv,ubuntu-12.04,opencv3.1,v4l,C++,Opencv,Ubuntu 12.04,Opencv3.1,V4l,以下是相关的捕获代码: int capture_frame(int doAlign){ try{ vector<int> compression_params; compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);//(CV_IMWRITE_PXM_BINARY); compression_params.push_back(0);

以下是相关的捕获代码:

    int capture_frame(int doAlign){

    try{

    vector<int> compression_params;
            compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);//(CV_IMWRITE_PXM_BINARY);
            compression_params.push_back(0);





        VideoCapture cap(cameranum); // open the default camera


        long
        c=0;
        while(!cap.isOpened()){ // check if we succeeded
           if (!cap.isOpened() && c < 3){
               sleep(1);
           }
           if (!cap.isOpened() && c >=3) return -1;
           c++;
        }//end while not opened

        cap.set(CV_CAP_PROP_FRAME_WIDTH, 1920);

        cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);


        Mat frame;
        Mat frame_gray;


        while(frame.empty()){
            for (int i=0; i < 10; i++) {cap >> frame;} // get a new frame from camera
        }



        cvtColor(frame, frame_gray, CV_BGR2GRAY); //make it gray



        Mat lastframe;
        Mat im2_aligned;



        stringstream filename;
        stringstream lastfilename;
        stringstream number;
        number << setfill('0') << setw(6) << currentframe;
        filename << directory << "frame" << number.str() << ".png";
        if (currentframe <1 || doAlign == 0) {

            imwrite(filename.str(), frame_gray, compression_params ); //frame vs frame_gray
            //cout << "contrast: " << cvGetCaptureProperty(cap,11) << endl;
        }else{
            number.str("");
            number << setfill('0') << setw(6) << currentframe-1;
            lastfilename << directory << "/frame" << number.str() << ".pgm";
            Mat im1= imread(lastfilename.str());
            Mat im1_gray;
            cvtColor(im1, im1_gray, CV_BGR2GRAY);

            // Define the motion model
            const int warp_mode = MOTION_TRANSLATION;

            // Set a 2x3 warp matrix
            Mat warp_matrix;
             warp_matrix = Mat::eye(2, 3, CV_32F);
             // Specify the number of iterations.
             int number_of_iterations = 5000;

             // Specify the threshold of the increment
             // in the correlation coefficient between two iterations
             double termination_eps = 1e-10;

             // Define termination criteria
             TermCriteria criteria (TermCriteria::COUNT+TermCriteria::EPS, number_of_iterations, termination_eps);

             // Run the ECC algorithm. The results are stored in warp_matrix.
             findTransformECC(im1_gray,frame_gray,warp_matrix,warp_mode,criteria);
             warpAffine(frame, im2_aligned, warp_matrix, im1.size(), INTER_LINEAR + WARP_INVERSE_MAP);
             Mat im2_aligned_gray;
             cvtColor(im2_aligned, im2_aligned_gray, CV_BGR2GRAY);
             imwrite(filename.str(), im2_aligned_gray, compression_params );
             cap.release();




        }//end if not first frame





        currentframe++;
        cap.release();
    }catch (cv::Exception ex){
        cout << " frame was bad! try again" << endl;
        return (0);
     }//end caught exception trying to load

        return (1);

}//end capture frame
int-capture\u帧(int-doAlign){
试一试{
矢量压缩参数;
压缩参数。向后推(CV_IMWRITE_PNG_compression);/(CV_IMWRITE_PXM_BINARY);
压缩参数向后推(0);
VideoCapture cap(cameranum);//打开默认摄像机
长的
c=0;
而(!cap.isopend()){//请检查我们是否成功
如果(!cap.isOpened()&&c<3){
睡眠(1);
}
如果(!cap.isOpened()&&c>=3)返回-1;
C++;
}//未打开时结束
封盖套件(CV、封盖、道具、框架、宽度,1920);
封盖套件(CV、封盖、支柱、框架、高度,1080);
垫架;
垫子框架为灰色;
while(frame.empty()){
对于(inti=0;i<10;i++){cap>>frame;}//从摄影机获取新帧
}
CVT颜色(边框,边框为灰色,CV为灰色);//使其为灰色
垫板框架;
Mat im2_对齐;
字符串流文件名;
stringstream lastfilename;
串流数;

数字帮助社区通过发布代码和错误消息输出来提供帮助,该错误消息输出引用了抛出错误的行。我在python中每隔几分钟就有一个循环读取一个视频帧,我得到了相同的错误。@cb4代码已添加