问题
I would like to save a captured image from my webcam attached BeagleBone Black, however when I run the following code, I get the error: select timeout.
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/videoio.hpp"
using namespace std;
using namespace cv;
int main(){
cout<< "Hello, OpenCV version: "<< CV_VERSION << endl;
Mat frame;
VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_WIDTH , 320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT , 240);
cap >> frame;
imwrite("camCap.jpg", frame);
return 0;
}
When I compile and run the code:
root@beaglebone:/home/iroh/test# g++ test.cpp -lopencv_core -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -o test
root@beaglebone:/home/iroh/test# ./test
Hello, OpenCV version: 3.1.0
select timeout
OpenCV Error: Assertion failed (total() == 0 || data != NULL) in Mat, file /home/iroh/Downloads/opencv-3.1.0/modules/core/include/opencv2/core/mat.inl.hpp, line 410
terminate called after throwing an instance of 'cv::Exception'
what(): /home/iroh/Downloads/opencv-3.1.0/modules/core/include/opencv2/core/mat.inl.hpp:410: error: (-215) total() == 0 || data != NULL in function Mat
Aborted
What can be the cause of that problem?
According to the error output, my frame is empty. It is first time I attached this webcam to BeagleBone Black. It works properly on my PC, but I do not know whether it is working successfully with BeagleBone Black.
Here is the dmesg output:
[ 4276.642456] usb 1-1: new high-speed USB device number 2 using musb-hdrc
[ 4277.411212] usb 1-1: New USB device found, idVendor=1e4e, idProduct=0110
[ 4277.411257] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 4277.411284] usb 1-1: Product: USB2.0 Camera
[ 4277.411310] usb 1-1: Manufacturer: Etron Technology, Inc.
[ 4277.532768] uvcvideo: Found UVC 1.00 device USB2.0 Camera (1e4e:0110)
[ 4277.542871] input: USB2.0 Camera as /devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.0/input/input1
[ 4277.547293] usbcore: registered new interface driver uvcvideo
[ 4277.547322] USB Video Class driver (1.1.1)
What shall I do?
Thanks!
回答1:
I was running into this same issue and managed to fix it. Check my answer here
回答2:
I met the same issue, I guess your working environment was Ubuntu system.
I changed my virtual machine setting "USB2.0 -> USB3.0".
Hope it helps you!
来源:https://stackoverflow.com/questions/37273453/image-capture-with-opencv-select-timeout-error