OpenCV Image Canny edge detection

Source: Internet
Author: User

Canny edge Detection

The image edge Detection principle is to detect all the gray values in the image of the larger changes in the point, and these points are connected to form a number of lines, these lines can be called the edge of the image
function Prototypes:

void Cvcanny (

Const cvarr* Image,//The first parameter represents an input image and must be a single-channel grayscale
cvarr* edges,///The second parameter represents the edge image of the output, which is a single-channel black -and-white image
Double Threshold1,
double threshold2,//The third parameter and the fourth parameter represent the threshold, and the small threshold values in these two thresholds are used to control the edge connection.
A large threshold is used to control the initial segmentation of a strong edge, which is considered if the gradient of a pixel is large and the upper limit is
is the edge pixel, which is discarded if it is less than the lower threshold value. If the gradient of the point is between the two, then this
The point is connected to a pixel above the upper limit and we do not retain it or delete it.
The int aperture_size=3//fifth parameter represents the size of the Sobel operator, and the default is 3, which represents a 3*3 matrix. Sobel operator and
Laplace operators are common edge operators.
    );
    
function function: Create TrackBar and add to specified window

function Prototypes:

Intcvcreatetrackbar (

Const char* Trackbar_name,//The first parameter represents the name of the trackbar.
Const char* Window_name,//The second parameter represents the window name, and the trackbar is displayed within this window.
int* value,//The third parameter represents the position of the slider at the time of creation.
int count,//fourth parameter represents the maximum value of the slider position, and the minimum value is fixed to 0.
The cvtrackbarcallback On_change//Fifth parameter represents a callback function. The callback function is called when there is a change in the position of the slider.
    );
Note: The created TrackBar is displayed by default at the top of the specified window and can be obtained by using the function Cvgettrackbarpos () .
TrackBar Displays the location information, as well as the function Cvsettrackbarpos () to reset the display position of the trackbar.

<CvTrackbarCallback>
function Function: The callback function used by the Cvcreatetrackbar () function

function Definition:
typedef void (CV_CDECL *cvtrackbarcallback) (int pos)

function Description:
when the trackbar position is changed, the system calls the callback function and sets the parameter pos to the value representing the trackbar position.

#include"stdafx.h"#include"iostream"using namespacestd; #include"opencv2/opencv.hpp"Iplimage*pgrayimage =Null;iplimage*pcannyimage =NULL;Const Char*pimagepath ="e:/c_vc_code/text_photo/girl001.jpg";Const Char*pgraywindowstitle ="Original";Const Char*pcannywindowstitle ="Edge detection Diagram";Const Char*pwindowstoolbartitle ="Valve Value";voidOnCallback (intPOS) {    //Canny CheckCvcanny (Pgrayimage, Pcannyimage, POS, pos*3,3); Cvshowimage (Pcannywindowstitle, pcannyimage);}intMain () {//load Gray image from Srcouce file imagePgrayimage =cvloadimage (Pimagepath, Cv_load_image_grayscale); Pcannyimage= Cvcreateimage (Cvgetsize (pgrayimage), ipl_depth_8u,1); //Create WindowCvnamedwindow (pgraywindowstitle,cv_window_autosize);    Cvnamedwindow (pcannywindowstitle,cv_window_autosize); //creat Slide Bar    intpos =1; Cvcreatetrackbar (Pwindowstoolbartitle, Pcannywindowstitle,&pos, -, OnCallback); OnCallback (0);    Cvshowimage (Pgraywindowstitle,pgrayimage);    Cvshowimage (Pcannywindowstitle,pcannyimage); Cvwaitkey (0);    Cvdestroywindow (Pcannywindowstitle);    Cvdestroywindow (Pgraywindowstitle); Cvreleaseimage (&pgrayimage); Cvreleaseimage (&pcannyimage); return 0;}

OpenCV Image Canny edge detection

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.