Added Laplace, Canny and Sobel samples in tutorial cpp code
This commit is contained in:
73
samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp
Normal file
73
samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @file CannyDetector_Demo.cpp
|
||||
* @brief Sample code showing how to detect edges using the Canny Detector
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
/// Global variables
|
||||
|
||||
Mat src, src_gray;
|
||||
Mat dst, detected_edges;
|
||||
|
||||
int edgeThresh = 1;
|
||||
int lowThreshold;
|
||||
int const max_lowThreshold = 100;
|
||||
int ratio = 3;
|
||||
int kernel_size = 3;
|
||||
char* window_name = "Edge Map";
|
||||
|
||||
/**
|
||||
* @function CannyThreshold
|
||||
* @brief Trackbar callback - Canny thresholds input with a ratio 1:3
|
||||
*/
|
||||
void CannyThreshold(int, void*)
|
||||
{
|
||||
/// Reduce noise with a kernel 3x3
|
||||
blur( src_gray, dst, Size(3,3) );
|
||||
|
||||
/// Canny detector
|
||||
Canny( src_gray, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
|
||||
|
||||
/// Using Canny's output as a mask, we display our result
|
||||
dst = Scalar::all(0);
|
||||
|
||||
src.copyTo( dst, detected_edges);
|
||||
imshow( window_name, dst );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load an image
|
||||
src = imread( argv[1] );
|
||||
|
||||
if( !src.data )
|
||||
{ return -1; }
|
||||
|
||||
/// Convert the image to grayscale
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
|
||||
/// Create a window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
|
||||
/// Create a Trackbar for user to enter threshold
|
||||
createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );
|
||||
|
||||
/// Show the image
|
||||
CannyThreshold(0, 0);
|
||||
|
||||
/// Wait until user exit program by pressing a key
|
||||
waitKey(0);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user