opencv/samples/cpp/polar_transforms.cpp

76 lines
2.3 KiB
C++
Raw Normal View History

2016-02-15 21:37:29 +08:00
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
2016-02-15 21:37:29 +08:00
using namespace cv;
2012-06-08 01:21:29 +08:00
static void help( void )
2010-12-03 10:31:20 +08:00
{
2012-10-17 15:12:04 +08:00
printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n"
"Usage :\n"
2016-02-15 21:37:29 +08:00
"./polar_transforms [[camera number -- Default 0],[path_to_filename]]\n\n");
2010-12-03 10:31:20 +08:00
}
2016-02-15 21:37:29 +08:00
int main( int argc, char** argv )
{
2016-02-15 21:37:29 +08:00
VideoCapture capture;
Mat log_polar_img, lin_polar_img, recovered_log_polar, recovered_lin_polar_img;
help();
2016-02-15 21:37:29 +08:00
CommandLineParser parser(argc, argv, "{@input|0|}");
2015-08-01 23:24:23 +08:00
std::string arg = parser.get<std::string>("@input");
2016-02-15 21:37:29 +08:00
2015-08-01 23:24:23 +08:00
if( arg.size() == 1 && isdigit(arg[0]) )
2016-02-15 21:37:29 +08:00
capture.open( arg[0] - '0' );
2015-08-01 23:24:23 +08:00
else
2016-02-15 21:37:29 +08:00
capture.open( arg.c_str() );
if( !capture.isOpened() )
{
2015-08-01 23:24:23 +08:00
const char* name = argv[0];
fprintf(stderr,"Could not initialize capturing...\n");
2015-08-01 23:24:23 +08:00
fprintf(stderr,"Usage: %s <CAMERA_NUMBER> , or \n %s <VIDEO_FILE>\n", name, name);
return -1;
}
2016-02-15 21:37:29 +08:00
namedWindow( "Linear-Polar", WINDOW_NORMAL );
namedWindow( "Log-Polar", WINDOW_NORMAL );
namedWindow( "Recovered Linear-Polar", WINDOW_NORMAL );
namedWindow( "Recovered Log-Polar", WINDOW_NORMAL );
2016-02-15 21:37:29 +08:00
moveWindow( "Linear-Polar", 20,20 );
moveWindow( "Log-Polar", 700,20 );
moveWindow( "Recovered Linear-Polar", 20, 350 );
moveWindow( "Recovered Log-Polar", 700, 350 );
for(;;)
{
2016-02-15 21:37:29 +08:00
Mat frame;
capture >> frame;
2016-02-15 21:37:29 +08:00
if( frame.empty() )
break;
2016-02-15 21:37:29 +08:00
Point2f center( (float)frame.cols / 2, (float)frame.rows / 2 );
double M = (double)frame.cols / 8;
2016-02-15 21:37:29 +08:00
logPolar(frame,log_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS);
linearPolar(frame,lin_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS);
2016-02-15 21:37:29 +08:00
logPolar(log_polar_img, recovered_log_polar, center, M, WARP_INVERSE_MAP + INTER_LINEAR);
linearPolar(lin_polar_img, recovered_lin_polar_img, center, M, WARP_INVERSE_MAP + INTER_LINEAR + WARP_FILL_OUTLIERS);
2016-02-15 21:37:29 +08:00
imshow("Log-Polar", log_polar_img );
imshow("Linear-Polar", lin_polar_img );
imshow("Recovered Linear-Polar", recovered_lin_polar_img );
imshow("Recovered Log-Polar", recovered_log_polar );
2016-02-15 21:37:29 +08:00
if( waitKey(10) >= 0 )
break;
}
2016-02-15 21:37:29 +08:00
waitKey(0);
return 0;
}