Saturday, June 27, 2015

Simple Canny Edge Detection with Trackbar

Posted by Md.Hanif Ali on Saturday, June 27, 2015 in | No comments

Canny Edge Detection in OpenCV:

In this tutorial you will learn how to use the OpenCV function Canny to implement the Canny Edge Detector.

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

 using namespace cv;
 int thresh=10;
 Mat gray_image, canny_image;

 void trackChange(int, void*);
int main()
{
    Mat img_rgb = imread( "c:/apple.jpg" );

    cvtColor( img_rgb, gray_image, CV_BGR2GRAY);
    namedWindow( "Gray Window", CV_WINDOW_AUTOSIZE );
    namedWindow( "Canny Window", CV_WINDOW_AUTOSIZE );

    createTrackbar("Threshold","Canny Window",&thresh,255,trackChange);
    trackChange(0,0);
    imshow( "Gray Window", gray_image ); //ksjdhfklashdfklhaskldhfklahskldfhkladshklfhsklahdfklhaskldhfklashdklfhsklafhklahfklhaklfhlkahfklhaklfhklahfklhaklfhlkashdflahs

    waitKey(0);
    return 0;
}

void trackChange(int, void*)
{
    Canny( gray_image, canny_image, 10, thresh, 3, true );
    imshow( "Canny Window", canny_image );
}
Output: 
Canny edge detection


0 comments:

Post a Comment