some samples updated according to new CommandLineParser class
[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                         "Call:\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     if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
24         capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
25     else if( argc == 2 )
26         capture = cvCaptureFromAVI( argv[1] );
27     help();
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         return -1;
33     }
34
35     cvNamedWindow( "Linear-Polar", 0 );
36     cvNamedWindow( "Log-Polar", 0 );
37     cvNamedWindow( "Recovered image", 0 );
38
39     cvMoveWindow( "Linear-Polar", 20,20 );
40     cvMoveWindow( "Log-Polar", 700,20 );
41     cvMoveWindow( "Recovered image", 20,700 );
42
43     for(;;)
44     {
45         IplImage* frame = 0;
46
47         frame = cvQueryFrame( capture );
48         if( !frame )
49             break;
50
51         if( !log_polar_img )
52         {
53             log_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
54             lin_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
55             recovered_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
56         }
57
58         cvLogPolar(frame,log_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
59         cvLinearPolar(frame,lin_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
60
61 #if 0
62                 cvLogPolar(log_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR);
63 #else
64         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);
65 #endif
66
67         cvShowImage("Log-Polar", log_polar_img );
68         cvShowImage("Linear-Polar", lin_polar_img );
69         cvShowImage("Recovered image", recovered_img );
70
71         if( cvWaitKey(10) >= 0 )
72             break;
73     }
74
75     cvReleaseCapture( &capture );
76     cvDestroyWindow("Linear-Polar");
77     cvDestroyWindow("Log-Polar");
78     cvDestroyWindow("Recovered image");
79
80     return 0;
81 }
82
83 #ifdef _EiC
84 main(1,"laplace.c");
85 #endif