polar_transforms.cpp 2.96 KB
Newer Older
a  
Kai Westerkamp committed
1 2 3 4
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/videoio/videoio_c.h"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/core/utility.hpp"
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();
a  
Kai Westerkamp committed
24 25 26 27 28 29
    cv::CommandLineParser parser(argc, argv, "{help h||}{@input|0|}");
    if (parser.has("help"))
    {
        help();
        return 0;
    }
wester committed
30 31
    std::string arg = parser.get<std::string>("@input");
    if( arg.size() == 1 && isdigit(arg[0]) )
a  
Kai Westerkamp committed
32
        capture = cvCaptureFromCAM( arg[0] - '0' );
wester committed
33
    else
a  
Kai Westerkamp committed
34 35
        capture = cvCaptureFromAVI( arg.c_str() );
    if( !capture )
wester committed
36 37 38 39
    {
        const char* name = argv[0];
        fprintf(stderr,"Could not initialize capturing...\n");
        fprintf(stderr,"Usage: %s <CAMERA_NUMBER>    , or \n       %s <VIDEO_FILE>\n", name, name);
a  
Kai Westerkamp committed
40
        help();
wester committed
41 42 43
        return -1;
    }

a  
Kai Westerkamp committed
44 45 46
    cvNamedWindow( "Linear-Polar", 0 );
    cvNamedWindow( "Log-Polar", 0 );
    cvNamedWindow( "Recovered image", 0 );
wester committed
47

a  
Kai Westerkamp committed
48 49 50
    cvMoveWindow( "Linear-Polar", 20,20 );
    cvMoveWindow( "Log-Polar", 700,20 );
    cvMoveWindow( "Recovered image", 20,700 );
wester committed
51 52 53

    for(;;)
    {
a  
Kai Westerkamp committed
54
        IplImage* frame = 0;
wester committed
55

a  
Kai Westerkamp committed
56 57
        frame = cvQueryFrame( capture );
        if( !frame )
wester committed
58 59
            break;

a  
Kai Westerkamp committed
60 61 62 63 64 65
        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
66

a  
Kai Westerkamp committed
67 68
        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
69

a  
Kai Westerkamp committed
70 71 72 73 74
#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
75

a  
Kai Westerkamp committed
76 77 78
        cvShowImage("Log-Polar", log_polar_img );
        cvShowImage("Linear-Polar", lin_polar_img );
        cvShowImage("Recovered image", recovered_img );
wester committed
79

a  
Kai Westerkamp committed
80
        if( cvWaitKey(10) >= 0 )
wester committed
81 82 83
            break;
    }

a  
Kai Westerkamp committed
84 85 86 87 88
    cvReleaseCapture( &capture );
    cvDestroyWindow("Linear-Polar");
    cvDestroyWindow("Log-Polar");
    cvDestroyWindow("Recovered image");

wester committed
89 90
    return 0;
}
a  
Kai Westerkamp committed
91 92 93 94

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