Advertisement
Guest User

syncvideo.cpp

a guest
Aug 6th, 2014
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright: Jan Kučera, 2014
  2. // Code available under GPLv3 license
  3. // License text available at: http://www.gnu.org/copyleft/gpl.html
  4.  
  5. #include "opencv2/opencv.hpp"
  6. #include <iostream>
  7. #include <fstream>
  8.  
  9. using namespace cv;
  10. using namespace std;
  11.  
  12. int main()
  13. {  
  14.     int index = 0;
  15.    
  16.     // open cameras
  17.     VideoCapture cap1(0);       // LEFT camera
  18.     VideoCapture cap2(1);       // RIGHT camera
  19.    
  20.     // check if we succeeded
  21.     if(!cap1.isOpened()) return -1;
  22.     if(!cap2.isOpened()) return -1;
  23.    
  24.     cap1.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
  25.     cap1.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
  26.     cap2.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
  27.     cap2.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
  28.    
  29.     // create windows
  30.     namedWindow("edges1",1);
  31.     namedWindow("edges2",1);
  32.    
  33.     long key;
  34.    
  35.     // create matrices for camera images
  36.     Mat frame1;
  37.     Mat frame2;
  38.    
  39.     // main loop
  40.     for(;;) {
  41.        
  42.         index++;
  43.        
  44.         // detect key pressed
  45.         key = waitKey(1000);
  46.        
  47.         // get a new frame from cameras
  48.         cap1 >> frame1;
  49.         cap2 >> frame2;
  50.        
  51.         // every Xth iteration
  52.         // if (index % 100 == 0) {
  53.  
  54.             // define variables for strings
  55.             std::string fileName1;
  56.             std::string fileName2;
  57.             // define variables for conversion of int to string
  58.             std::stringstream string1;
  59.             std::stringstream string2;
  60.            
  61.             // create file paths and names from constant and numbered index
  62.             string1 << "images/image_L_" << index << ".ppm";
  63.             string2 << "images/image_R_" << index << ".ppm";
  64.            
  65.             // convert it to string
  66.             fileName1 = string1.str();
  67.             fileName2 = string2.str();
  68.            
  69.             // save image files
  70.             // imwrite(fileName1, frame1);
  71.             // imwrite(fileName2, frame2);
  72.         // }
  73.        
  74.         // downscale to 33%
  75.         Size imageSize(640,360);
  76.         resize(frame1,frame1,imageSize);
  77.         resize(frame2,frame2,imageSize);
  78.        
  79.         // show camera images
  80.         imshow("edges1", frame1);
  81.         imshow("edges2", frame2);
  82.        
  83.         // if key was pressed
  84.         if (key >= 0) {
  85.            
  86.             // if ESC is pressed - quit
  87.             if (key == 1048603) {
  88.                 return 0;
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement