HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP solution

question:

       Recently, I was studying the problem of using a monocular camera to obtain depth. After writing a program to take pictures with a camera in python, I ran it, and the error shown in the title appeared:

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

The solution was found in this blog: HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP error solution

Solution:

1. Install the following dependencies:

sudo apt-get install libv4l-dev 

sudo apt-get install v4l2ucp

sudo apt-get install v4l-utils


2. Reinstall opencv after installing the following dependencies

To install opencv refer to this article:Configuration and installation of Opencv 2.4.9 under Ubuntu

On the computer where opencv has been installed, just recompile and install opencv, enter the release folder of opencv, and perform the following steps:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

make 

sudo make install

sudo ldconfig -v

After reinstalling opencv, the program runs successfully.


The reasons for the above problems are:

After the necessary dependency libraries such as val/v4l2 are installed in opencv, the opencv library is not compiled into it when compiling, so after reinstalling the dependencies, recompile opencv

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856227&siteId=291194637