opencv/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp

65 lines
1.3 KiB
C++
Raw Normal View History

/**
* @file Laplace_Demo.cpp
* @brief Sample code showing how to detect edges using the Laplace operator
* @author OpenCV team
*/
2016-02-15 21:37:29 +08:00
#include "opencv2/imgproc.hpp"
2014-07-04 22:48:15 +08:00
#include "opencv2/imgcodecs.hpp"
2016-02-15 21:37:29 +08:00
#include "opencv2/highgui.hpp"
using namespace cv;
/**
* @function main
*/
2017-07-26 13:39:53 +08:00
int main( int argc, char** argv )
{
2016-07-18 21:32:05 +08:00
//![variables]
Mat src, src_gray, dst;
2012-10-17 07:18:30 +08:00
int kernel_size = 3;
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
const char* window_name = "Laplace Demo";
2016-07-18 21:32:05 +08:00
//![variables]
2016-07-18 21:32:05 +08:00
//![load]
2017-07-26 13:39:53 +08:00
String imageName("../data/lena.jpg"); // by default
if (argc > 1)
{
imageName = argv[1];
}
src = imread( imageName, IMREAD_COLOR ); // Load an image
if( src.empty() )
{ return -1; }
2016-07-18 21:32:05 +08:00
//![load]
2016-07-18 21:32:05 +08:00
//![reduce_noise]
/// Reduce noise by blurring with a Gaussian filter
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
2016-07-18 21:32:05 +08:00
//![reduce_noise]
2016-07-18 21:32:05 +08:00
//![convert_to_gray]
cvtColor( src, src_gray, COLOR_BGR2GRAY ); // Convert the image to grayscale
//![convert_to_gray]
/// Apply Laplace function
Mat abs_dst;
2016-07-18 21:32:05 +08:00
//![laplacian]
Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
2016-07-18 21:32:05 +08:00
//![laplacian]
//![convert]
convertScaleAbs( dst, abs_dst );
2016-07-18 21:32:05 +08:00
//![convert]
2016-07-18 21:32:05 +08:00
//![display]
imshow( window_name, abs_dst );
waitKey(0);
2016-07-18 21:32:05 +08:00
//![display]
return 0;
}