X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=samples%2Fc%2Flaplace.c;h=3a45f27c2f132368d088ff7be732554fe2e6a4df;hb=e4c14cdbdf2fe805e79cd96ded236f57e7b89060;hp=3626c41d3edb925562244cd55f0aca4fd399baf3;hpb=454138ff8a20f6edb9b65a910101403d8b520643;p=opencv diff --git a/samples/c/laplace.c b/samples/c/laplace.c index 3626c41..3a45f27 100644 --- a/samples/c/laplace.c +++ b/samples/c/laplace.c @@ -2,6 +2,8 @@ #pragma package #endif +#define CV_NO_BACKWARD_COMPATIBILITY + #ifndef _EiC #include "cv.h" #include "highgui.h" @@ -9,30 +11,34 @@ #include #endif +int sigma = 3; +int smoothType = CV_GAUSSIAN; + int main( int argc, char** argv ) { IplImage* laplace = 0; IplImage* colorlaplace = 0; IplImage* planes[3] = { 0, 0, 0 }; CvCapture* capture = 0; - + 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] ); + capture = cvCaptureFromAVI( argv[1] ); if( !capture ) { fprintf(stderr,"Could not initialize capturing...\n"); return -1; } - + cvNamedWindow( "Laplacian", 0 ); + cvCreateTrackbar( "Sigma", "Laplacian", &sigma, 15, 0 ); for(;;) { IplImage* frame = 0; - int i; + int i, c, ksize; frame = cvQueryFrame( capture ); if( !frame ) @@ -41,23 +47,28 @@ int main( int argc, char** argv ) if( !laplace ) { for( i = 0; i < 3; i++ ) - planes[i] = cvCreateImage( cvSize(frame->width,frame->height), 8, 1 ); - laplace = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_16S, 1 ); - colorlaplace = cvCreateImage( cvSize(frame->width,frame->height), 8, 3 ); + planes[i] = cvCreateImage( cvGetSize(frame), 8, 1 ); + laplace = cvCreateImage( cvGetSize(frame), IPL_DEPTH_16S, 1 ); + colorlaplace = cvCreateImage( cvGetSize(frame), 8, 3 ); } - cvCvtPixToPlane( frame, planes[0], planes[1], planes[2], 0 ); + ksize = (sigma*5)|1; + cvSmooth( frame, colorlaplace, smoothType, ksize, ksize, sigma, sigma ); + cvSplit( colorlaplace, planes[0], planes[1], planes[2], 0 ); for( i = 0; i < 3; i++ ) { - cvLaplace( planes[i], laplace, 3 ); - cvConvertScaleAbs( laplace, planes[i], 1, 0 ); + cvLaplace( planes[i], laplace, 5 ); + cvConvertScaleAbs( laplace, planes[i], (sigma+1)*0.25, 0 ); } - cvCvtPlaneToPix( planes[0], planes[1], planes[2], 0, colorlaplace ); + cvMerge( planes[0], planes[1], planes[2], 0, colorlaplace ); colorlaplace->origin = frame->origin; cvShowImage("Laplacian", colorlaplace ); - if( cvWaitKey(10) >= 0 ) + c = cvWaitKey(30); + if( c == ' ' ) + smoothType = smoothType == CV_GAUSSIAN ? CV_BLUR : smoothType == CV_BLUR ? CV_MEDIAN : CV_GAUSSIAN; + if( c == 'q' || c == 'Q' || (c & 255) == 27 ) break; }