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