View difference between Paste ID: siUbeqqB and tE6y2tF5
SHOW: | | - or go back to the newest paste.
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-
// Program:
5+
6-
// saving stereo stills from webcam in PPM image format for stereo calibration
6+
7
#include <fstream>
8
9
using namespace cv;
10
using namespace std;
11
12
int main()
13
{	
14
	int index = 0;
15
	
16-
{
16+
17
	VideoCapture cap1(0); 		// LEFT camera
18-
	ofstream myfile;
18+
	VideoCapture cap2(1);		// RIGHT camera
19-
	myfile.open ("filelist.txt");
19+
20
	// check if we succeeded
21
	if(!cap1.isOpened()) return -1;
22
	if(!cap2.isOpened()) return -1;
23-
	// 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 
23+
24
	cap1.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
25
	cap1.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
26-
	VideoCapture cap1(1); 		// LEFT camera
26+
	cap2.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
27-
	VideoCapture cap2(0);		// RIGHT camera
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-
		// create matrices for camera images
40+
41-
		Mat frame1;
41+
42-
		Mat frame2;
42+
		index++;
43
		
44
		// detect key pressed
45-
		long key = waitKey(1000);
45+
		key = waitKey(1000);
46
		
47
		// get a new frame from cameras
48-
		cap1 >> frame1; 	
48+
		cap1 >> frame1;
49
		cap2 >> frame2;
50
		
51
		// every Xth iteration
52
		// if (index % 100 == 0) {
53
54
			// define variables for strings
55-
		// waitkey was originaly here
55+
			std::string fileName1;
56
			std::string fileName2;
57-
		// for debugging - print key code
57+
			// define variables for conversion of int to string
58-
		// std::cout << "Key code: " << key;
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-
				myfile.close();
65+
			// convert it to string
66
			fileName1 = string1.str();
67
			fileName2 = string2.str();
68
			
69-
			// if SPACE pressed - save images
69+
			// save image files
70-
			if (key == 1048608) {
70+
			// imwrite(fileName1, frame1);
71-
				
71+
			// imwrite(fileName2, frame2);
72-
				// increment counter
72+
		// }
73-
				index++;
73+
74-
				
74+
		// downscale to 33%
75-
				// define variables for strings
75+
		Size imageSize(640,360);
76-
				std::string fileName1;
76+
		resize(frame1,frame1,imageSize);
77-
				std::string fileName2;
77+
		resize(frame2,frame2,imageSize);
78-
				// define variables for conversion of int to string
78+
79-
				std::stringstream string1;
79+
80-
				std::stringstream string2;
80+
81-
				
81+
82-
				// create file paths and names from constant and numbered index
82+
83-
				// string1 << "images/image_L_" << index << ".ppm";
83+
84-
				// string2 << "images/image_R_" << index << ".ppm";
84+
85-
				string1 << "images/image_L_" << index << ".jpg";
85+
86-
				string2 << "images/image_R_" << index << ".jpg";
86+
87-
				
87+
88-
				// convert it to string
88+
89-
				fileName1 = string1.str();
89+
90-
				fileName2 = string2.str();
90+
91-
				
91+
92-
				// save image files
92+