Ask Your Question

Revision history [back]

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");

}

click to hide/show revision 2
None

updated 2017-11-21 04:48:05 -0600

berak gravatar image

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"

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";

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");

}

}