Skip to content

Instantly share code, notes, and snippets.

@RDCH106
Last active January 20, 2016 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RDCH106/2dc3be1cf2e9344ba65b to your computer and use it in GitHub Desktop.
Save RDCH106/2dc3be1cf2e9344ba65b to your computer and use it in GitHub Desktop.
Display 2 Images in 1 Window with OpenCV
#include "opencv2/opencv.hpp"
int display(){
//cv::VideoCapture cap1(0); // open the default camera
cv::VideoCapture cap1(0); // open the first camera
cv::VideoCapture cap2(1); // open the second camera
if(!cap1.isOpened()) // check if we succeeded
return -1;
if(!cap2.isOpened()) // check if we succeeded
return -1;
for(;;)
{
cv::Mat frame1, frame2;
cap1 >> frame1; // get a new frame from camera
cap2 >> frame2; // get a new frame from camera
cv::Mat display (frame1.size().height, frame1.size().width + frame2.size().width, CV_8UC3) ;
cv::Mat left(display, cv::Rect(0, 0, frame1.size().width, frame1.size().height));
frame1.copyTo(left);
cv::Mat right(display, cv::Rect(frame1.size().width, 0, frame2.size().width, frame2.size().height));
frame2.copyTo(right);
cv::imshow("Display", display);
int key = cv::waitKey(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment