1 #include "opencv2/videoio/videoio.hpp"
2 #include "opencv2/highgui/highgui.hpp"
3 #include "opencv2/imgproc/imgproc.hpp"
15 "\nThis program demonstrates Laplace point/edge detection using OpenCV function Laplacian()\n"
16 "It captures from the camera of your choice: 0, 1, ... default 0\n"
18 "./laplace [camera #, default 0]\n" << endl;
21 enum {GAUSSIAN, BLUR, MEDIAN};
24 int smoothType = GAUSSIAN;
26 int main( int argc, char** argv )
31 if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
32 cap.open(argc == 2 ? argv[1][0] - '0' : 0);
37 cout << "Video " << argv[1] <<
38 ": width=" << cap.get(CAP_PROP_FRAME_WIDTH) <<
39 ", height=" << cap.get(CAP_PROP_FRAME_HEIGHT) <<
40 ", nframes=" << cap.get(CAP_PROP_FRAME_COUNT) << endl;
41 if( argc > 2 && isdigit(argv[2][0]) )
44 sscanf(argv[2], "%d", &pos);
45 cout << "seeking to frame #" << pos << endl;
46 cap.set(CAP_PROP_POS_FRAMES, pos);
52 cout << "Could not initialize capturing...\n";
56 namedWindow( "Laplacian", 0 );
57 createTrackbar( "Sigma", "Laplacian", &sigma, 15, 0 );
59 Mat smoothed, laplace, result;
68 int ksize = (sigma*5)|1;
69 if(smoothType == GAUSSIAN)
70 GaussianBlur(frame, smoothed, Size(ksize, ksize), sigma, sigma);
71 else if(smoothType == BLUR)
72 blur(frame, smoothed, Size(ksize, ksize));
74 medianBlur(frame, smoothed, ksize);
76 Laplacian(smoothed, laplace, CV_16S, 5);
77 convertScaleAbs(laplace, result, (sigma+1)*0.25);
78 imshow("Laplacian", result);
82 smoothType = smoothType == GAUSSIAN ? BLUR : smoothType == BLUR ? MEDIAN : GAUSSIAN;
83 if( c == 'q' || c == 'Q' || (c & 255) == 27 )