Update to 2.0.0 tree from current Fremantle build
[opencv] / samples / c / laplace.c
1 #ifdef _CH_
2 #pragma package <opencv>
3 #endif
4
5 #define CV_NO_BACKWARD_COMPATIBILITY
6
7 #ifndef _EiC
8 #include "cv.h"
9 #include "highgui.h"
10 #include <ctype.h>
11 #include <stdio.h>
12 #endif
13
14 int sigma = 3;
15 int smoothType = CV_GAUSSIAN;
16
17 int main( int argc, char** argv )
18 {
19     IplImage* laplace = 0;
20     IplImage* colorlaplace = 0;
21     IplImage* planes[3] = { 0, 0, 0 };
22     CvCapture* capture = 0;
23
24     if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
25         capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
26     else if( argc == 2 )
27         capture = cvCaptureFromAVI( argv[1] );
28
29     if( !capture )
30     {
31         fprintf(stderr,"Could not initialize capturing...\n");
32         return -1;
33     }
34
35     cvNamedWindow( "Laplacian", 0 );
36     cvCreateTrackbar( "Sigma", "Laplacian", &sigma, 15, 0 );
37
38     for(;;)
39     {
40         IplImage* frame = 0;
41         int i, c, ksize;
42
43         frame = cvQueryFrame( capture );
44         if( !frame )
45             break;
46
47         if( !laplace )
48         {
49             for( i = 0; i < 3; i++ )
50                 planes[i] = cvCreateImage( cvGetSize(frame), 8, 1 );
51             laplace = cvCreateImage( cvGetSize(frame), IPL_DEPTH_16S, 1 );
52             colorlaplace = cvCreateImage( cvGetSize(frame), 8, 3 );
53         }
54
55         ksize = (sigma*5)|1;
56         cvSmooth( frame, colorlaplace, smoothType, ksize, ksize, sigma, sigma );
57         cvSplit( colorlaplace, planes[0], planes[1], planes[2], 0 );
58         for( i = 0; i < 3; i++ )
59         {
60             cvLaplace( planes[i], laplace, 5 );
61             cvConvertScaleAbs( laplace, planes[i], (sigma+1)*0.25, 0 );
62         }
63         cvMerge( planes[0], planes[1], planes[2], 0, colorlaplace );
64         colorlaplace->origin = frame->origin;
65
66         cvShowImage("Laplacian", colorlaplace );
67
68         c = cvWaitKey(30);
69         if( c == ' ' )
70             smoothType = smoothType == CV_GAUSSIAN ? CV_BLUR : smoothType == CV_BLUR ? CV_MEDIAN : CV_GAUSSIAN;
71         if( c == 'q' || c == 'Q' || (c & 255) == 27 )
72             break;
73     }
74
75     cvReleaseCapture( &capture );
76     cvDestroyWindow("Laplacian");
77
78     return 0;
79 }
80
81 #ifdef _EiC
82 main(1,"laplace.c");
83 #endif