Update the trunk to the OpenCV's CVS (2008-07-14)
[opencv] / samples / c / laplace.c
1 #ifdef _CH_
2 #pragma package <opencv>
3 #endif
4
5 #ifndef _EiC
6 #include "cv.h"
7 #include "highgui.h"
8 #include <ctype.h>
9 #include <stdio.h>
10 #endif
11
12 int main( int argc, char** argv )
13 {
14     IplImage* laplace = 0;
15     IplImage* colorlaplace = 0;
16     IplImage* planes[3] = { 0, 0, 0 };
17     CvCapture* capture = 0;
18     
19     if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
20         capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
21     else if( argc == 2 )
22         capture = cvCaptureFromAVI( argv[1] ); 
23
24     if( !capture )
25     {
26         fprintf(stderr,"Could not initialize capturing...\n");
27         return -1;
28     }
29         
30     cvNamedWindow( "Laplacian", 0 );
31
32     for(;;)
33     {
34         IplImage* frame = 0;
35         int i;
36
37         frame = cvQueryFrame( capture );
38         if( !frame )
39             break;
40
41         if( !laplace )
42         {
43             for( i = 0; i < 3; i++ )
44                 planes[i] = cvCreateImage( cvSize(frame->width,frame->height), 8, 1 );
45             laplace = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_16S, 1 );
46             colorlaplace = cvCreateImage( cvSize(frame->width,frame->height), 8, 3 );
47         }
48
49         cvCvtPixToPlane( frame, planes[0], planes[1], planes[2], 0 );
50         for( i = 0; i < 3; i++ )
51         {
52             cvLaplace( planes[i], laplace, 3 );
53             cvConvertScaleAbs( laplace, planes[i], 1, 0 );
54         }
55         cvCvtPlaneToPix( planes[0], planes[1], planes[2], 0, colorlaplace );
56         colorlaplace->origin = frame->origin;
57
58         cvShowImage("Laplacian", colorlaplace );
59
60         if( cvWaitKey(10) >= 0 )
61             break;
62     }
63
64     cvReleaseCapture( &capture );
65     cvDestroyWindow("Laplacian");
66
67     return 0;
68 }
69
70 #ifdef _EiC
71 main(1,"laplace.c");
72 #endif