Canny edge detection in images
Edge detection is the foundation practice with Computer Vision. To detect edges OpenCV has cvCanny function.
Syntax
void cvCanny(const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture size=3 );
Parameters :
edges | Single-channel image to store the edges found by the function |
threshold1 | The first threshold |
threshold2 | The second threshold. |
aperture | size Aperture parameter for the Sobel operator. |
Example
#include "cv.h" #include "highgui.h" int main( int argc, char** argv ) { IplImage* img_rgb = cvLoadImage("Desert1.jpg"); // create another image IplImage* img_gry = cvCreateImage( cvSize( img_rgb->width,img_rgb->height ), img_rgb->depth, 1); // convert rgb to gray cvCvtColor(img_rgb, img_gry ,CV_BGR2GRAY); // initialize windows to show image cvNamedWindow("Gray Image", CV_WINDOW_AUTOSIZE ); cvNamedWindow("Canny Edge Detector", CV_WINDOW_AUTOSIZE ); cvShowImage("Gray Image", img_gry ); // Canny Edge Detector cvCanny( img_gry, img_gry, 10, 100, 3); cvShowImage("Canny Edge Detector", img_gry); cvWaitKey(0); cvReleaseImage( &img_rgb); cvReleaseImage( &img_gry); cvDestroyWindow("Gray Image"); cvDestroyWindow("Canny Edge Detector"); }