diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 9b88221f02..b190c124f4 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -1192,6 +1192,7 @@ protected: /** @example lsd_lines.cpp An example using the LineSegmentDetector +\image html building_lsd.png "Sample output image" width=434 height=300 */ /** @brief Line segment detector class @@ -1347,6 +1348,11 @@ operation is shifted. */ CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1)); +/** @example Smoothing.cpp +Sample code for simple filters +![Sample screenshot](Smoothing_Tutorial_Result_Median_Filter.jpg) +Check @ref tutorial_gausian_median_blur_bilateral_filter "the corresponding tutorial" for more details + */ /** @brief Blurs an image using the median filter. The function smoothes an image using the median filter with the \f$\texttt{ksize} \times @@ -1549,6 +1555,11 @@ CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth, Point anchor = Point(-1,-1), double delta = 0, int borderType = BORDER_DEFAULT ); +/** @example Sobel_Demo.cpp +Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector +![Sample screenshot](Sobel_Derivatives_Tutorial_Result.jpg) +Check @ref tutorial_sobel_derivatives "the corresponding tutorial" for more details + */ /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to @@ -1681,7 +1692,9 @@ CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth, //! @{ /** @example edge.cpp - An example on using the canny edge detector + This program demonstrates usage of the Canny edge detector + + Check @ref tutorial_canny_detector "the corresponding tutorial" for more details */ /** @brief Finds edges in an image using the Canny algorithm @cite Canny86 . @@ -1908,6 +1921,7 @@ CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, /** @example houghlines.cpp An example using the Hough line detector +![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg) */ /** @brief Finds lines in a binary image using the standard Hough transform. @@ -2105,7 +2119,9 @@ CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles, //! @{ /** @example morphology2.cpp - An example using the morphological operations +Advanced morphology Transformations sample code +![Sample screenshot](Morphology_2_Tutorial_Result.jpg) +Check @ref tutorial_opening_closing_hats "the corresponding tutorial" for more details */ /** @brief Erodes an image by using a specific structuring element. @@ -2135,6 +2151,11 @@ CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue() ); +/** @example Morphology_1.cpp +Erosion and Dilation sample code +![Sample Screenshot-Erosion](Morphology_1_Tutorial_Erosion_Result.jpg)![Sample Screenshot-Dilation](Morphology_1_Tutorial_Dilation_Result.jpg) +Check @ref tutorial_erosion_dilatation "the corresponding tutorial" for more details + */ /** @brief Dilates an image by using a specific structuring element. The function dilates the source image using the specified structuring element that determines the @@ -3377,6 +3398,7 @@ CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst, /** @example grabcut.cpp An example using the GrabCut algorithm +![Sample Screenshot](grabcut_output1.jpg) */ /** @brief Runs the GrabCut algorithm. @@ -4399,7 +4421,8 @@ CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts, int thickness = 1, int lineType = LINE_8, int shift = 0 ); /** @example contours2.cpp - An example using the drawContour functionality + An example program illustrates the use of cv::findContours and cv::drawContours + \image html WindowsQtContoursOutput.png "Screenshot of the program" */ /** @example segment_objects.cpp diff --git a/modules/objdetect/include/opencv2/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect.hpp index 0747d67661..85fad544a2 100644 --- a/modules/objdetect/include/opencv2/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect.hpp @@ -216,6 +216,8 @@ public: }; /** @example facedetect.cpp +This program demonstrates usage of the Cascade classifier class +\image html Cascade_Classifier_Tutorial_Result_Haar.jpg "Sample screenshot" width=321 height=254 */ /** @brief Cascade classifier class for object detection. */ diff --git a/samples/cpp/facedetect.cpp b/samples/cpp/facedetect.cpp index 86d3284fc2..d7bdfcff01 100644 --- a/samples/cpp/facedetect.cpp +++ b/samples/cpp/facedetect.cpp @@ -8,7 +8,7 @@ using namespace cv; static void help() { - cout << "\nThis program demonstrates the cascade recognizer. Now you can use Haar or LBP features.\n" + cout << "\nThis program demonstrates the use of cv::CascadeClassifier class to detect objects (Face + eyes). You can use Haar or LBP features.\n" "This classifier can recognize many kinds of rigid objects, once the appropriate classifier is trained.\n" "It's most known use is for faces.\n" "Usage:\n" diff --git a/samples/cpp/lsd_lines.cpp b/samples/cpp/lsd_lines.cpp index e0db6c3669..a5c7326639 100644 --- a/samples/cpp/lsd_lines.cpp +++ b/samples/cpp/lsd_lines.cpp @@ -1,38 +1,50 @@ -#include - #include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" +#include using namespace std; using namespace cv; int main(int argc, char** argv) { - std::string in; - cv::CommandLineParser parser(argc, argv, "{@input|../data/building.jpg|input image}{help h||show help message}"); - if (parser.has("help")) + cv::CommandLineParser parser(argc, argv, + "{input i|../data/building.jpg|input image}" + "{refine r|false|if true use LSD_REFINE_STD method, if false use LSD_REFINE_NONE method}" + "{canny c|false|use Canny edge detector}" + "{overlay o|false|show result on input image}" + "{help h|false|show help message}"); + + if (parser.get("help")) { parser.printMessage(); return 0; } - in = parser.get("@input"); - Mat image = imread(in, IMREAD_GRAYSCALE); + parser.printMessage(); + + String filename = parser.get("input"); + bool useRefine = parser.get("refine"); + bool useCanny = parser.get("canny"); + bool overlay = parser.get("overlay"); + + Mat image = imread(filename, IMREAD_GRAYSCALE); if( image.empty() ) - { return -1; } + { + cout << "Unable to load " << filename; + return 1; + } -#if 0 - Canny(image, image, 50, 200, 3); // Apply canny edge -#endif + imshow("Source Image", image); + + if (useCanny) + { + Canny(image, image, 50, 200, 3); // Apply Canny edge detector + } // Create and LSD detector with standard or no refinement. -#if 1 - Ptr ls = createLineSegmentDetector(LSD_REFINE_STD); -#else - Ptr ls = createLineSegmentDetector(LSD_REFINE_NONE); -#endif + Ptr ls = useRefine ? createLineSegmentDetector(LSD_REFINE_STD) : createLineSegmentDetector(LSD_REFINE_NONE); double start = double(getTickCount()); vector lines_std; @@ -44,9 +56,17 @@ int main(int argc, char** argv) std::cout << "It took " << duration_ms << " ms." << std::endl; // Show found lines - Mat drawnLines(image); - ls->drawSegments(drawnLines, lines_std); - imshow("Standard refinement", drawnLines); + if (!overlay || useCanny) + { + image = Scalar(0, 0, 0); + } + + ls->drawSegments(image, lines_std); + + String window_name = useRefine ? "Result - standard refinement" : "Result - no refinement"; + window_name += useCanny ? " - Canny edge detector used" : ""; + + imshow(window_name, image); waitKey(); return 0; diff --git a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp index d5a3776aa7..5209380414 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp @@ -1,6 +1,6 @@ /** * @file Sobel_Demo.cpp - * @brief Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector + * @brief Sample code uses Sobel or Scharr OpenCV functions for edge detection * @author OpenCV team */ @@ -8,70 +8,110 @@ #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" +#include + using namespace cv; +using namespace std; /** * @function main */ int main( int argc, char** argv ) { + cv::CommandLineParser parser(argc, argv, + "{@input |../data/lena.jpg|input image}" + "{ksize k|1|ksize (hit 'K' to increase its value)}" + "{scale s|1|scale (hit 'S' to increase its value)}" + "{delta d|0|delta (hit 'D' to increase its value)}" + "{help h|false|show help message}"); + + cout << "The sample uses Sobel or Scharr OpenCV functions for edge detection\n\n"; + parser.printMessage(); + cout << "\nPress 'ESC' to exit program.\nPress 'R' to reset values ( ksize will be -1 equal to Scharr function )"; + //![variables] - Mat src, src_gray; + Mat image,src, src_gray; Mat grad; - const char* window_name = "Sobel Demo - Simple Edge Detector"; - int scale = 1; - int delta = 0; + const String window_name = "Sobel Demo - Simple Edge Detector"; + int ksize = parser.get("ksize"); + int scale = parser.get("scale"); + int delta = parser.get("delta"); int ddepth = CV_16S; //![variables] //![load] - String imageName("../data/lena.jpg"); // by default - if (argc > 1) + String imageName = parser.get("@input"); // by default + image = imread( imageName, IMREAD_COLOR ); // Load an image + + if( image.empty() ) { - imageName = argv[1]; + return 1; } - src = imread( imageName, IMREAD_COLOR ); // Load an image - - if( src.empty() ) - { return -1; } //![load] - //![reduce_noise] - GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT ); - //![reduce_noise] + for (;;) + { + //![reduce_noise] + GaussianBlur(image, src, Size(3, 3), 0, 0, BORDER_DEFAULT); + //![reduce_noise] - //![convert_to_gray] - cvtColor( src, src_gray, COLOR_BGR2GRAY ); - //![convert_to_gray] + //![convert_to_gray] + cvtColor(src, src_gray, COLOR_BGR2GRAY); + //![convert_to_gray] - //![sobel] - /// Generate grad_x and grad_y - Mat grad_x, grad_y; - Mat abs_grad_x, abs_grad_y; + //![sobel] + /// Generate grad_x and grad_y + Mat grad_x, grad_y; + Mat abs_grad_x, abs_grad_y; - /// Gradient X - //Scharr( src_gray, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT ); - Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT ); + /// Gradient X + Sobel(src_gray, grad_x, ddepth, 1, 0, ksize, scale, delta, BORDER_DEFAULT); - /// Gradient Y - //Scharr( src_gray, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT ); - Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT ); - //![sobel] + /// Gradient Y + Sobel(src_gray, grad_y, ddepth, 0, 1, ksize, scale, delta, BORDER_DEFAULT); + //![sobel] - //![convert] - convertScaleAbs( grad_x, abs_grad_x ); - convertScaleAbs( grad_y, abs_grad_y ); - //![convert] + //![convert] + convertScaleAbs(grad_x, abs_grad_x); + convertScaleAbs(grad_y, abs_grad_y); + //![convert] - //![blend] - /// Total Gradient (approximate) - addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad ); - //![blend] + //![blend] + /// Total Gradient (approximate) + addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad); + //![blend] - //![display] - imshow( window_name, grad ); - waitKey(0); - //![display] + //![display] + imshow(window_name, grad); + char key = (char)waitKey(0); + //![display] + if(key == 27) + { + return 0; + } + + if (key == 'k' || key == 'K') + { + ksize = ksize < 30 ? ksize+2 : -1; + } + + if (key == 's' || key == 'S') + { + scale++; + } + + if (key == 'd' || key == 'D') + { + delta++; + } + + if (key == 'r' || key == 'R') + { + scale = 1; + ksize = -1; + delta = 0; + } + } return 0; }