OPENCV Official Document Learning record (16)

Source: Internet
Author: User

Canny edge Detection

Not to mention function, to code:

1#include <opencv2\opencv.hpp>2#include <iostream>3#include <string>4 5 #pragmaComment (linker, "/subsystem:\" windows\ "/entry:\" Maincrtstartup\ "")6 7 using namespacestd;8 using namespaceCV;9 Ten intMainvoid) One { A     //Loading Pictures -Mat src = imread ("lena.jpg"); -     if(Src.empty ()) the         return-1; -Namedwindow ("src", cv_window_autosize); -Imshow ("src", SRC); -  +     //build the result picture in the original image format - Mat DST; + dst.create (Src.size (), Src.type ()); A  at     //Grayscale Conversion - Mat Src_gray; - cvtcolor (SRC, Src_gray, cv_bgr2gray); -Namedwindow ("Step 1-src_gray", cv_window_autosize); -Imshow ("Step 1-src_gray", Src_gray); -  in     intThreshold = -; -     intKernel_size =3; to     //Defining proportions +     intRatio =3; -  the     //Gaussian transform, noise reduction * Mat detected_edges; $Blur (Src_gray, Detected_edges, Size (3,3));Panax NotoginsengNamedwindow ("Step 2-detected_edges", cv_window_autosize); -Imshow ("Step 2-detected_edges", detected_edges); the  +     //Apply Canny transform, use the picture after noise reduction (Canny recommended a upper:lower ratio between 2:1 and 3:1.* from document *) ACanny (Detected_edges, detected_edges, Threshold, threshold*ratio, kernel_size); theNamedwindow ("Step 3-detected_edges", cv_window_autosize); +Imshow ("Step 3-detected_edges", detected_edges); -  $     //Fill with 0 $DST = Scalar::all (0); -  -     //to mask processing the Src.copyto (DST, detected_edges); - WuyiNamedwindow ("DST", cv_window_autosize); theImshow ("DST", DST); -  Wu Waitkey (); -     return 0; About}

Let's take a look at the notes and know about them.

Then analyze the output:

Analyze the last two outputs we know that this is the second to the bottom directly on the original image, only in those areas that are not black will be revealed, the beginning of the penultimate is the detection of the edge.

To achieve this effect is copyto this function, there are two parameters of the first parameter is through the source image and the second parameter together, when the second parameter corresponds to the pixel is not a black point, is not the pixel is 0 o'clock, the src copy to DST, in other cases, the 0 copy to DST, So there will be such an output.

Others are easier to understand.

Also note the threshold threshold, the smaller the value is set, the more the edge lines are displayed:

is 10 o'clock

is 50 o'clock

Because according to the function definition, the threshold value is that the result of the calculation is higher than the threshold value is considered to be the edge, so the larger the threshold, the more points will be sifted out.

Above.

OPENCV Official Document Learning record (16)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.