The virtual machine Ubuntu failed to open the camera and the OpenCV opened the camera timed out

Platform Version: Ubuntu 14.04 + Opencv 3.4.0

    Recently, I started to use opencv to realize face recognition, and encountered some problems: after installing the opencv library on the virtual machine Ubuntu, the official sample samples/cpp/example_cmake was compiled successfully, but the operation failed! ! !

Error output:

Built with OpenCV 3.4.0
Capture is opened
select timeout
select timeout
OpenCV Error: Assertion failed (total() == 0 || data != __null) in Mat, file /root/library/opencv/opencv-3.4.0/modules/core/include/opencv2/core/mat.inl.hpp, line 500
terminate called after throwing an instance of 'cv::Exception'
  what():  /root/library/opencv/opencv-3.4.0/modules/core/include/opencv2/core/mat.inl.hpp:500: error: (-215) total() == 0 || data != __null in function Mat

Abandoned (core dumped)

Turn on the camera timed out! ! !

What is the reason for this?

First of all, of course, it was Baidu, but I couldn't find a solution. Forget it, it's up to you.

The occurrence of problems is generally not due to code problems. After all, it is an example given by the official. There are enough reasons to believe that it is reliable.

That could be: installation problem of the library? Camera problem? other? ? ?

If it is a library problem, find a simple and reliable HelloWorld program to test it.

Here I directly predict that it is the camera problem!


1. The virtual machine Ubuntu detects whether the camera has been inserted normally

    Plug in the USB camera, but no video device is found under /dev? It's because the camera is connected to the host, not the virtual machine. Therefore, the device needs to be moved to the virtual machine.

    The virtual machine connects to the camera: 

"Virtual Machine (M) -> Removable Device (D) -> Logitech USB Camera -> Connect (disconnect from host)"

    You can find that there is a video0 device under /dev.


2. Open the camera on the virtual machine Ubuntu

    How to turn on camera on Ubuntu? Here you need to install a software "cheese".

1. Install " cheese" and turn on the camera

    " cheese" is a camera that uses the camera to take pictures and video, and can use some fancy special effects, which allows you to share your fun with others.

    Install:    $ sudo apt-get install cheese

    Run:    $ cheese


    Found that the camera light is on, but the picture is black (wait for a while or an incomplete image will appear and it will freeze)

    Ubuntu fails to open the camera, no wonder opencv times out to open the camera. The problem should be here! ! !

    Baidu can find a solution to this problem.

2. Set up the virtual machine and successfully open the camera

    Open "Virtual Machine (M) -> Settings (S)" on the virtual machine

    Click "USB Controller" and replace "USB Compatibility (C)" : if it is USB 2.0, replace it with USB 3.0, if it is USB 3.0, replace it with USB 2.0.

    After the setup is complete, the virtual machine will automatically restart.

3. Run "cheese" again to turn on the camera

    First disconnect the virtual machine's camera, and then reconnect it. (see above for operation)

    Running cheese, the result is as follows:


Camera turned on successfully!


3. OpenCV opens the camera

    Go back to  samples/cpp/example_cmake,

    Compile and run:

    $ cmake . & make & ./samples/cpp/example_cmake

    

    Done, call it a day!


    Remarks: This blog is designed to solve the problem of [ Ubuntu14.04 install Opencv3.4.0 ]

Guess you like

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