Tutorial Laplace Operator

This commit is contained in:
tribta
2017-08-22 00:17:09 +01:00
parent d068e27420
commit 3250f11f0c
5 changed files with 292 additions and 56 deletions
@@ -15,50 +15,53 @@ using namespace cv;
*/
int main( int argc, char** argv )
{
//![variables]
Mat src, src_gray, dst;
int kernel_size = 3;
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
const char* window_name = "Laplace Demo";
//![variables]
//![variables]
// Declare the variables we are going to use
Mat src, src_gray, dst;
int kernel_size = 3;
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
const char* window_name = "Laplace Demo";
//![variables]
//![load]
String imageName("../data/lena.jpg"); // by default
if (argc > 1)
{
imageName = argv[1];
}
src = imread( imageName, IMREAD_COLOR ); // Load an image
//![load]
const char* imageName = argc >=2 ? argv[1] : "../data/lena.jpg";
if( src.empty() )
{ return -1; }
//![load]
src = imread( imageName, IMREAD_COLOR ); // Load an image
//![reduce_noise]
/// Reduce noise by blurring with a Gaussian filter
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
//![reduce_noise]
// Check if image is loaded fine
if(src.empty()){
printf(" Error opening image\n");
printf(" Program Arguments: [image_name -- default ../data/lena.jpg] \n");
return -1;
}
//![load]
//![convert_to_gray]
cvtColor( src, src_gray, COLOR_BGR2GRAY ); // Convert the image to grayscale
//![convert_to_gray]
//![reduce_noise]
// Reduce noise by blurring with a Gaussian filter ( kernel size = 3 )
GaussianBlur( src, src, Size(3, 3), 0, 0, BORDER_DEFAULT );
//![reduce_noise]
/// Apply Laplace function
Mat abs_dst;
//![laplacian]
Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
//![laplacian]
//![convert_to_gray]
cvtColor( src, src_gray, COLOR_BGR2GRAY ); // Convert the image to grayscale
//![convert_to_gray]
//![convert]
convertScaleAbs( dst, abs_dst );
//![convert]
/// Apply Laplace function
Mat abs_dst;
//![laplacian]
Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
//![laplacian]
//![display]
imshow( window_name, abs_dst );
waitKey(0);
//![display]
//![convert]
// converting back to CV_8U
convertScaleAbs( dst, abs_dst );
//![convert]
return 0;
//![display]
imshow( window_name, abs_dst );
waitKey(0);
//![display]
return 0;
}