Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright: Jan Kučera, 2014
- // Code available under GPLv3 license
- // License text available at: http://www.gnu.org/copyleft/gpl.html
- #include "opencv2/opencv.hpp"
- #include <iostream>
- #include <fstream>
- using namespace cv;
- using namespace std;
- int main()
- {
- int index = 0;
- // open cameras
- VideoCapture cap1(0); // LEFT camera
- VideoCapture cap2(1); // RIGHT camera
- // check if we succeeded
- if(!cap1.isOpened()) return -1;
- if(!cap2.isOpened()) return -1;
- cap1.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
- cap1.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
- cap2.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
- cap2.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
- // create windows
- namedWindow("edges1",1);
- namedWindow("edges2",1);
- long key;
- // create matrices for camera images
- Mat frame1;
- Mat frame2;
- // main loop
- for(;;) {
- index++;
- // detect key pressed
- key = waitKey(1000);
- // get a new frame from cameras
- cap1 >> frame1;
- cap2 >> frame2;
- // every Xth iteration
- // if (index % 100 == 0) {
- // define variables for strings
- std::string fileName1;
- std::string fileName2;
- // define variables for conversion of int to string
- std::stringstream string1;
- std::stringstream string2;
- // create file paths and names from constant and numbered index
- string1 << "images/image_L_" << index << ".ppm";
- string2 << "images/image_R_" << index << ".ppm";
- // convert it to string
- fileName1 = string1.str();
- fileName2 = string2.str();
- // save image files
- // imwrite(fileName1, frame1);
- // imwrite(fileName2, frame2);
- // }
- // downscale to 33%
- Size imageSize(640,360);
- resize(frame1,frame1,imageSize);
- resize(frame2,frame2,imageSize);
- // show camera images
- imshow("edges1", frame1);
- imshow("edges2", frame2);
- // if key was pressed
- if (key >= 0) {
- // if ESC is pressed - quit
- if (key == 1048603) {
- return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement