-
Notifications
You must be signed in to change notification settings - Fork 902
/
example_02-11.cpp
76 lines (53 loc) · 1.73 KB
/
example_02-11.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Example 2-11. A complete program to read in a color video and write out the log-polar-
// transformed video
#include <opencv2/opencv.hpp>
#include <iostream>
void help(char** argv ) {
std::cout << "\n"
<< "Read in a video, write out a log polar of it\n"
<< argv[0] <<" <path/video> <paht/video_output>\n"
<< "For example:\n"
<< argv[0] << " ../tree.avi ../vout.avi\n"
<< "\nThen read it with:\n ./example_02-10 ../vout.avi\n"
<< std::endl;
}
int main( int argc, char** argv ) {
if (argc != 3) {
help(argv);
return 0;
}
cv::namedWindow( "Example 2-11", cv::WINDOW_AUTOSIZE );
cv::namedWindow( "Log_Polar", cv::WINDOW_AUTOSIZE );
// ( Note: could capture from a camera by giving a camera id as an int.)
//
cv::VideoCapture capture( argv[1] );
double fps = capture.get( CV_CAP_PROP_FPS );
cv::Size size(
(int)capture.get( CV_CAP_PROP_FRAME_WIDTH ),
(int)capture.get( CV_CAP_PROP_FRAME_HEIGHT )
);
cv::VideoWriter writer;
writer.open( argv[2], CV_FOURCC('M','J','P','G'), fps, size );
cv::Mat logpolar_frame, bgr_frame;
for(;;) {
capture >> bgr_frame;
if( bgr_frame.empty() ) break; // end if done
cv::imshow( "Example 2-11", bgr_frame );
cv::logPolar(
bgr_frame, // Input color frame
logpolar_frame, // Output log-polar frame
cv::Point2f( // Centerpoint for log-polar transformation
bgr_frame.cols/2, // x
bgr_frame.rows/2 // y
),
40, // Magnitude (scale parameter)
CV_WARP_FILL_OUTLIERS // Fill outliers with 'zero'
);
cv::imshow( "Log_Polar", logpolar_frame );
writer << logpolar_frame;
char c = cv::waitKey(10);
if( c == 27 ) break; // allow the user to break out
}
writer.release();
capture.release();
}