Update to 2.0.0 tree from current Fremantle build
[opencv] / samples / octave / laplace.m
1 #! /usr/bin/env octave
2 addpath("/home/x/opencv2/interfaces/swig/octave");
3 source("/home/x/opencv2/interfaces/swig/octave/PKG_ADD_template");
4 debug_on_error(true);
5 debug_on_warning(true);
6 crash_dumps_octave_core (0)
7 cv;
8 highgui;
9
10 laplace = [];
11 colorlaplace = [];
12 planes = { [], [], [] };
13 capture = [];
14
15 if (size(argv, 2)==0)
16   capture = cvCreateCameraCapture( -1 );
17 elseif (size(argv, 2)==1 && all(isdigit(argv(){1})))
18   capture = cvCreateCameraCapture( int32(argv(){1}) );
19 elseif (size(argv, 2)==1)
20   capture = cvCreateFileCapture( argv(){1} );
21 endif
22
23 if (!swig_this(capture))
24   printf("Could not initialize capturing...\n");
25   exit(-1)
26 endif
27
28 cvNamedWindow( "Laplacian", 1 );
29
30 while (true),
31   frame = cvQueryFrame( capture );
32   if (!swig_this(frame))
33     break
34   endif
35
36   if (!swig_this(laplace))
37     for i=1:size(planes,2),
38       planes{i} = cvCreateImage( \
39                                 cvSize(frame.width,frame.height), \
40                                 8, 1 );
41     endfor
42     laplace = cvCreateImage( cvSize(frame.width,frame.height), IPL_DEPTH_16S, 1 );
43     colorlaplace = cvCreateImage( \
44                                  cvSize(frame.width,frame.height), \
45                                  8, 3 );
46   endif
47
48   cvSplit( frame, planes{1}, planes{2}, planes{3}, [] );
49   for plane = planes,
50     plane = plane{1};
51     cvLaplace( plane, laplace, 3 );
52     cvConvertScaleAbs( laplace, plane, 1, 0 );
53   endfor
54
55   cvMerge( planes{1}, planes{2}, planes{3}, [], colorlaplace );
56 #  colorlaplace.origin = frame.origin;
57
58   cvShowImage("Laplacian", colorlaplace );
59
60   if (cvWaitKey(10) == 27)
61     break;
62   endif
63 endwhile
64
65 cvDestroyWindow("Laplacian");