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
- // Program:
- // saving stereo stills from webcam in PPM image format for stereo calibration
- #include "opencv2/opencv.hpp"
- #include <iostream>
- #include <fstream>
- using namespace cv;
- using namespace std;
- int main()
- {
- ofstream myfile;
- myfile.open ("filelist.txt");
- int index = 0;
- // note: camera sides (LEFT and RIGHT) are considered when you are FACING the cameras (looking into their lens), not from camera's point of view
- // open cameras
- VideoCapture cap1(1); // LEFT camera
- VideoCapture cap2(0); // RIGHT camera
- // check if we succeeded
- if(!cap1.isOpened()) return -1;
- if(!cap2.isOpened()) return -1;
- // create windows
- namedWindow("edges1",1);
- namedWindow("edges2",1);
- // main loop
- for(;;) {
- // create matrices for camera images
- Mat frame1;
- Mat frame2;
- // detect key pressed
- long key = waitKey(1000);
- // get a new frame from cameras
- cap1 >> frame1;
- cap2 >> frame2;
- // show camera images
- imshow("edges1", frame1);
- imshow("edges2", frame2);
- // waitkey was originaly here
- // for debugging - print key code
- // std::cout << "Key code: " << key;
- // if key was pressed
- if (key >= 0) {
- // if ESC is pressed - quit
- if (key == 1048603) {
- myfile.close();
- return 0;
- }
- // if SPACE pressed - save images
- if (key == 1048608) {
- // increment counter
- index++;
- // 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";
- string1 << "images/image_L_" << index << ".jpg";
- string2 << "images/image_R_" << index << ".jpg";
- // convert it to string
- fileName1 = string1.str();
- fileName2 = string2.str();
- // save image files
- imwrite(fileName1, frame1);
- imwrite(fileName2, frame2);
- myfile << fileName1 << "\n";
- myfile << fileName2 << "\n";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement