Opencv 3.1 capture from multiple cameras.
I'm using 2 Logitech C170 usb webcams connected to USB 3.0 ports on my front panel on Windows 10 Opencv 3.1 Visual Studio 2015. I have no problem getting image from one camera at a time either 0 or 1 but while I'm trying to get both at the same time i get a message:
R doesn't work
in console which is linked to second camera not working in the same time, followed by error:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow
Code I'm using:
#include <opencv2\opencv.hpp>
#include <opencv\highgui.h>
using namespace cv;
using namespace std;
int main()
{
VideoCapture captureL(0);
if (!captureL.isOpened()) cout << "L doesn't work" << endl;
VideoCapture captureR(1);
if (!captureR.isOpened()) cout << "R doesn't work" << endl;
Mat imageL, imageR;
while (1)
{
captureL >> imageL;
captureR >> imageR;
imshow("OriginalL", imageL);
imshow("OriginalR", imageR);
waitKey(1);
}
captureL.release();
captureR.release();
return 0;
}
Is there any way to fix that? It must be possible to get multiple captures at once. Maybe I'm doing something wrong since it is the newest Opencv 3.1.
I dont't think that this is an OpenCV problem. It is more likely a hardware problem. USB webcams tend to use as much usb bandwidth as possible. So if your two cameras are connected to the same usb bus, the first webcam will take all the bandwidth and there is no space left for the second webcam. Maybe you could use two different usb hosts to connect both webcams.
I just took your advice and seems like it was the problem, I've tried every possible combination plugging it in the back of my pc and finally it worked!
That is the problem of USB cameras as stated before. Get yourself a decent stereo setup with firewire camera's or something else with a dedicated data line to each cam. Using seperate USB busses (one in the front, one in the back of your PC) is only a partial solution.