Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/opencv.hpp>
- #include <vector>
- #define ZERO_LEFT true
- using namespace cv;
- using namespace std;
- int main(int argc, char** argv)
- {
- VideoCapture cap0(0), cap1(1);//to capture the camera frames
- Mat left, right, composite;//The images
- std::vector<Mat> channelsLeft, channelsRight, channelsComposite(3);
- namedWindow("Display", CV_WINDOW_NORMAL);
- for(int i = 0; i < 30; ++i)//bleed off any initial images; they're often crap
- {
- cap0 >> left;
- cap1 >> right;
- }
- for(;;)//main loop. I saw a stack exchange argument on why for(;;) is better than while(true). Don't know if I agree, but whatever.
- {
- if(ZERO_LEFT)// if /dev/video0 is the left camera
- {
- cap0 >> left;//pull the images
- cap1 >> right;
- }
- else// /dev/video1 is the left camera
- {
- cap1 >> left;
- cap0 >> right;
- }
- split(left, channelsLeft);//split the images into their channels
- split(right, channelsRight);
- //OpenCV uses blue green red color order. Blue and green planes should come from the right image, red from the left.
- channelsComposite[0] = channelsRight[0];
- channelsComposite[1] = channelsRight[1];
- channelsComposite[2] = channelsLeft[2];
- //stuff those channels back together
- merge(channelsComposite, composite);
- //and display them. But imshow doesn't actually show images...
- imshow("Display", composite);
- //waitKey does. Blame OpenCV for terrible design here. Really, it's just terrible.
- if(waitKey(1) != -1)//check if a key was pressed
- break;//and exit
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment