1 #include "opencv2/imgproc/imgproc_c.h"
2 #include "opencv2/videoio/videoio_c.h"
3 #include "opencv2/highgui/highgui_c.h"
4
5 #include <ctype.h>
6 #include <stdio.h>
7
help(void)8 static void help( void )
9 {
10 printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n"
11 "Usage :\n"
12 "./polar_transforms [[camera number -- Default 0],[AVI path_filename]]\n\n"
13 );
14 }
main(int argc,char ** argv)15 int main( int argc, char** argv )
16 {
17 CvCapture* capture = 0;
18 IplImage* log_polar_img = 0;
19 IplImage* lin_polar_img = 0;
20 IplImage* recovered_img = 0;
21
22 help();
23
24 if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
25 capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
26 else if( argc == 2 )
27 capture = cvCaptureFromAVI( argv[1] );
28 if( !capture )
29 {
30 fprintf(stderr,"Could not initialize capturing...\n");
31 fprintf(stderr,"Usage: %s <CAMERA_NUMBER> , or \n %s <VIDEO_FILE>\n",argv[0],argv[0]);
32 help();
33 return -1;
34 }
35
36 cvNamedWindow( "Linear-Polar", 0 );
37 cvNamedWindow( "Log-Polar", 0 );
38 cvNamedWindow( "Recovered image", 0 );
39
40 cvMoveWindow( "Linear-Polar", 20,20 );
41 cvMoveWindow( "Log-Polar", 700,20 );
42 cvMoveWindow( "Recovered image", 20,700 );
43
44 for(;;)
45 {
46 IplImage* frame = 0;
47
48 frame = cvQueryFrame( capture );
49 if( !frame )
50 break;
51
52 if( !log_polar_img )
53 {
54 log_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
55 lin_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
56 recovered_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
57 }
58
59 cvLogPolar(frame,log_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
60 cvLinearPolar(frame,lin_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
61
62 #if 0
63 cvLogPolar(log_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR);
64 #else
65 cvLinearPolar(lin_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
66 #endif
67
68 cvShowImage("Log-Polar", log_polar_img );
69 cvShowImage("Linear-Polar", lin_polar_img );
70 cvShowImage("Recovered image", recovered_img );
71
72 if( cvWaitKey(10) >= 0 )
73 break;
74 }
75
76 cvReleaseCapture( &capture );
77 cvDestroyWindow("Linear-Polar");
78 cvDestroyWindow("Log-Polar");
79 cvDestroyWindow("Recovered image");
80
81 return 0;
82 }
83
84 #ifdef _EiC
85 main(1,"laplace.c");
86 #endif
87