polar_transforms.c 2.76 KB
Newer Older
wester committed
1 2 3
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

a  
Kai Westerkamp committed
4
#include "opencv2/imgproc/imgproc_c.h"
wester committed
5

a  
Kai Westerkamp committed
6 7
#include <ctype.h>
#include <stdio.h>
wester committed
8 9 10 11 12

static void help( void )
{
    printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n"
            "Usage :\n"
a  
Kai Westerkamp committed
13 14
            "./polar_transforms [[camera number -- Default 0],[AVI path_filename]]\n\n"
            );
wester committed
15 16 17
}
int main( int argc, char** argv )
{
a  
Kai Westerkamp committed
18 19 20 21
    CvCapture* capture = 0;
    IplImage*  log_polar_img = 0;
    IplImage*  lin_polar_img = 0;
    IplImage*  recovered_img = 0;
wester committed
22 23

    help();
wester committed
24 25 26 27 28

    if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
        capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
    else if( argc == 2 )
        capture = cvCaptureFromAVI( argv[1] );
a  
Kai Westerkamp committed
29
    if( !capture )
wester committed
30 31
    {
        fprintf(stderr,"Could not initialize capturing...\n");
wester committed
32
        fprintf(stderr,"Usage: %s <CAMERA_NUMBER>    , or \n       %s <VIDEO_FILE>\n",argv[0],argv[0]);
a  
Kai Westerkamp committed
33
        help();
wester committed
34 35 36
        return -1;
    }

a  
Kai Westerkamp committed
37 38 39
    cvNamedWindow( "Linear-Polar", 0 );
    cvNamedWindow( "Log-Polar", 0 );
    cvNamedWindow( "Recovered image", 0 );
wester committed
40

a  
Kai Westerkamp committed
41 42 43
    cvMoveWindow( "Linear-Polar", 20,20 );
    cvMoveWindow( "Log-Polar", 700,20 );
    cvMoveWindow( "Recovered image", 20,700 );
wester committed
44 45 46

    for(;;)
    {
a  
Kai Westerkamp committed
47
        IplImage* frame = 0;
wester committed
48

a  
Kai Westerkamp committed
49 50
        frame = cvQueryFrame( capture );
        if( !frame )
wester committed
51 52
            break;

a  
Kai Westerkamp committed
53 54 55 56 57 58
        if( !log_polar_img )
        {
            log_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
            lin_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
            recovered_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
        }
wester committed
59

a  
Kai Westerkamp committed
60 61
        cvLogPolar(frame,log_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
        cvLinearPolar(frame,lin_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
wester committed
62

a  
Kai Westerkamp committed
63 64 65 66 67
#if 0
        cvLogPolar(log_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR);
#else
        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);
#endif
wester committed
68

a  
Kai Westerkamp committed
69 70 71
        cvShowImage("Log-Polar", log_polar_img );
        cvShowImage("Linear-Polar", lin_polar_img );
        cvShowImage("Recovered image", recovered_img );
wester committed
72

a  
Kai Westerkamp committed
73
        if( cvWaitKey(10) >= 0 )
wester committed
74 75 76
            break;
    }

a  
Kai Westerkamp committed
77 78 79 80 81
    cvReleaseCapture( &capture );
    cvDestroyWindow("Linear-Polar");
    cvDestroyWindow("Log-Polar");
    cvDestroyWindow("Recovered image");

wester committed
82 83
    return 0;
}
a  
Kai Westerkamp committed
84 85 86 87

#ifdef _EiC
main(1,"laplace.c");
#endif