I’ve been trying to capture a live video stream from a USB Cam using the simplest cookbook example from OpenCV (C++), but I’m getting errors:
The code:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main() {
VideoCapture stream1(0);
if (!stream1.isOpened()) {
cout << "cannot open camera";
}
while (true) {
Mat cameraFrame;
stream1.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(30) >= 0)
break;
}
return 0;
}
I’m getting an error:
Unable to stop the stream.: Device or resource busy
Unable to stop the stream.: Bad file descriptor
VIDIOC_STREAMON: Bad file descriptor
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /hdd/buildbot/slave_jetson_tx_2/35-O4T-L4T-Jetson-L/opencv/modules/highgui/src/window.cpp, line 261
terminate called after throwing an instance of 'cv::Exception'
what(): /hdd/buildbot/slave_jetson_tx_2/35-O4T-L4T-Jetson-L/opencv/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow
Aborted
I have tried this on two separate TX1 dev boards, with two different usb cams, and I’m getting the same results. Note that I can see the USB cam in /sys/class/video4linux/ and it is indeed device 0, and I can see a live feed in cheese, the video capture program that comes with ubuntu.
I actually have the same problem now and Tegra X2 is my platform. Tegra X1 also has some strange behavior in detection of the same camera but it is detecting now on Tegra X1.
For a simple code to get camera frames on Tegra X2 I get the following error :
libv4l2: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Device or resource busy
libv4l1: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l1: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT
and regardless of the fact that Tegra X2 has many installation problems (ex, Jetpack3 does not install GPU functions so you have to build it again) and it is solved now on another thread, it is my problem to get my camera to use now :(
I have installed all of the libraries and have no idea why Tegra X2 thinks my camera is BUSY all the time :/