Connecting 2 camera for stereo vision
Hello. I do not know what to do when one camera is connected is working perfectly. But when I connect the second camera, the system outputs one frame and freezes.
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /opt/opencv/modules/highgui/src/window.cpp, line 331
terminate called after throwing an instance of 'cv::Exception'
what(): /opt/opencv/modules/highgui/src/window.cpp:331: error: (-215) size.width>0 && size.height>0 in function imshow
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "opencv2/opencv.hpp"
/*
git clone https://github.com/opencv/opencv.git
mkdir build
cd build
cmake
make -j
sudo make install
*/
int main(int argc, char **argv)
{
//const char *pipeline = "tcambin serial=10710002 ! video/x-raw, format=GRAY8, framerate=30/1, width=640, height=480 ! videoconvert ! appsink";
//const char *pipeline = "v4l2src ! video/x-raw, format=GRAY8, width=640, height=480, framerate=30/1 ! videoconvert ! appsink";
//const char *pipeline = "videotestsrc ! appsink";
const char *pipeline_left = "tcamsrc serial=19710151 ! video/x-bayer,width=640, height=480 ! bayer2rgb ! videoconvert ! appsink";
const char *pipeline_right = "tcamsrc serial=19710152 ! video/x-bayer,width=640, height=480 ! bayer2rgb ! videoconvert ! appsink";
cv::VideoCapture *cap_1 = new cv::VideoCapture(pipeline_left);
cv::VideoCapture *cap_2 = new cv::VideoCapture(pipeline_right);
if (!cap_1->isOpened())
{
printf("Error can't create video capture left");
return 1;
}
if (!cap_2->isOpened())
{
printf("Error can't create video capture right");
return 1;
}
cv::namedWindow("Left",1);
cv::namedWindow("Right",1);
for(;;)
{
cv::Mat frame_left;
cv::Mat frame_right;
*cap_1 >> frame_left; // get a new frame from camera
*cap_2 >> frame_right;
cv::imshow("Left", frame_left);
cv::imshow("Right", frame_right);
char c= cv::waitKey(20);
if(c ==' ')
break;
}
delete cap_1;
delete cap_2;
cv::destroyWindow("Left");
cv::destroyWindow("Right");
}
one of your captures failed / was closed. add checks like:
then, it's time to analyze which one it was, and why.
If the cameras are used separately, they work. I do not know where to look for an error
I use a similar stereo vision system and opencv code, it works without problem.
Did you try to open cameras directly using the V4L path? Something like:
If you are afraid not to mix up the cameras, you can use the
/dev/by-path/...
ot/dev/by-id/...
path.