update cpp samples and tutorials

This commit is contained in:
Suleyman TURKMEN
2016-02-15 15:37:29 +02:00
parent 1aeff45631
commit 11ca1c95f8
110 changed files with 394 additions and 423 deletions

View File

@@ -1,94 +1,75 @@
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/videoio/videoio_c.h"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/core/utility.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
#include <ctype.h>
#include <stdio.h>
using namespace cv;
static void help( void )
{
printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n"
"Usage :\n"
"./polar_transforms [[camera number -- Default 0],[AVI path_filename]]\n\n"
);
"./polar_transforms [[camera number -- Default 0],[path_to_filename]]\n\n");
}
int main( int argc, char** argv )
{
CvCapture* capture = 0;
IplImage* log_polar_img = 0;
IplImage* lin_polar_img = 0;
IplImage* recovered_img = 0;
VideoCapture capture;
Mat log_polar_img, lin_polar_img, recovered_log_polar, recovered_lin_polar_img;
help();
cv::CommandLineParser parser(argc, argv, "{help h||}{@input|0|}");
if (parser.has("help"))
{
help();
return 0;
}
CommandLineParser parser(argc, argv, "{@input|0|}");
std::string arg = parser.get<std::string>("@input");
if( arg.size() == 1 && isdigit(arg[0]) )
capture = cvCaptureFromCAM( arg[0] - '0' );
capture.open( arg[0] - '0' );
else
capture = cvCaptureFromAVI( arg.c_str() );
if( !capture )
capture.open( arg.c_str() );
if( !capture.isOpened() )
{
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);
help();
return -1;
}
cvNamedWindow( "Linear-Polar", 0 );
cvNamedWindow( "Log-Polar", 0 );
cvNamedWindow( "Recovered image", 0 );
namedWindow( "Linear-Polar", WINDOW_NORMAL );
namedWindow( "Log-Polar", WINDOW_NORMAL );
namedWindow( "Recovered Linear-Polar", WINDOW_NORMAL );
namedWindow( "Recovered Log-Polar", WINDOW_NORMAL );
cvMoveWindow( "Linear-Polar", 20,20 );
cvMoveWindow( "Log-Polar", 700,20 );
cvMoveWindow( "Recovered image", 20,700 );
moveWindow( "Linear-Polar", 20,20 );
moveWindow( "Log-Polar", 700,20 );
moveWindow( "Recovered Linear-Polar", 20, 350 );
moveWindow( "Recovered Log-Polar", 700, 350 );
for(;;)
{
IplImage* frame = 0;
Mat frame;
capture >> frame;
frame = cvQueryFrame( capture );
if( !frame )
if( frame.empty() )
break;
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 );
}
Point2f center( (float)frame.cols / 2, (float)frame.rows / 2 );
double M = (double)frame.cols / 8;
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);
logPolar(frame,log_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS);
linearPolar(frame,lin_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS);
#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
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);
cvShowImage("Log-Polar", log_polar_img );
cvShowImage("Linear-Polar", lin_polar_img );
cvShowImage("Recovered image", recovered_img );
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 );
if( cvWaitKey(10) >= 0 )
if( waitKey(10) >= 0 )
break;
}
cvReleaseCapture( &capture );
cvDestroyWindow("Linear-Polar");
cvDestroyWindow("Log-Polar");
cvDestroyWindow("Recovered image");
waitKey(0);
return 0;
}
#ifdef _EiC
main(1,"laplace.c");
#endif