Guest User

Red/Cyan Anaglyph

a guest
Aug 26th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <opencv2/opencv.hpp>
  2. #include <vector>
  3.  
  4. #define ZERO_LEFT true
  5.  
  6. using namespace cv;
  7. using namespace std;
  8.  
  9. int main(int argc, char** argv)
  10. {
  11.     VideoCapture cap0(0), cap1(1);//to capture the camera frames
  12.     Mat left, right, composite;//The images
  13.     std::vector<Mat> channelsLeft, channelsRight, channelsComposite(3);
  14.     namedWindow("Display", CV_WINDOW_NORMAL);
  15.    
  16.     for(int i = 0; i < 30; ++i)//bleed off any initial images; they're often crap
  17.     {
  18.         cap0 >> left;
  19.         cap1 >> right;
  20.     }
  21.    
  22.     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.
  23.     {
  24.         if(ZERO_LEFT)// if /dev/video0 is the left camera
  25.         {
  26.             cap0 >> left;//pull the images
  27.             cap1 >> right;
  28.         }
  29.         else// /dev/video1 is the left camera
  30.         {
  31.             cap1 >> left;
  32.             cap0 >> right;
  33.         }
  34.         split(left, channelsLeft);//split the images into their channels
  35.         split(right, channelsRight);
  36.         //OpenCV uses blue green red color order.  Blue and green planes should come from the right image, red from the left.
  37.         channelsComposite[0] = channelsRight[0];
  38.         channelsComposite[1] = channelsRight[1];
  39.         channelsComposite[2] = channelsLeft[2];
  40.         //stuff those channels back together
  41.         merge(channelsComposite, composite);
  42.         //and display them.  But imshow doesn't actually show images...
  43.         imshow("Display", composite);
  44.         //waitKey does.  Blame OpenCV for terrible design here.  Really, it's just terrible.
  45.         if(waitKey(1) != -1)//check if a key was pressed
  46.             break;//and exit
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment