HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP错误解决方法

在树莓派上运行在windows上正确的程序,  报错:

HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/pi/Documents/opencv-2.4.13/modules/highgui/src/window.cpp, line 261
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/pi/Documents/opencv-2.4.13/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

Aborted

解决方法:

 方法一: 安装v4l2ucp, v4l-utils 和 libv4l-dev.    对我来说没用。

 方法二: 在视频imshow图像前,增加判断语句      

        while(true){
             capture >>Image;
         if(!Image.empty()){
        imshow("Test",Image);
        imwrite("test.jpg",Image);
         }
             
             if(waitKey(10) >= 0)break;
        }

然后,  只报错第一行,  但是程序可以正常运行。

之后,有出现了这个问题,仔细查阅,发现原因为

val/v4l2等必要的依赖库安装在opencv之后,opencv库编译时没有编译进去

因此,应在安装了依赖库后,重新安装opencv,重新cmake、make、makeinstall等。

原文地址:https://www.cnblogs.com/farewell-farewell/p/7138111.html