Opencv – How to do canny edge detection in javacv/opencv

edge detectionimage processingjavacvopencv

I'm currently working on image processing project and I need to detect edges from image. I thought to use canny edge detection for detect lines of the image, So i searched about canny edge detection using javacv on internet and I found some tutorials which gives the basic idea about canny edge detection technique but I could not be able to find any sample code regarding this. Please can someone provide simple sample edge detection code ?

It’s really appreciate if you can provide code example for following image.

enter image description here

Best Answer

For canny edge detection you need to perform like following.

IplImage gray = ...

cvCvtColor(colored, gray, CV_RGB2GRAY); 
cvSmooth( gray, smooth, CV_BLUR, 9, 9, 2, 2);   
cvThreshold(gray,gray, 155, 255, CV_THRESH_BINARY);

cvCanny( gray, gray, lowThreshold, highThreshold, aperature_size );  

Check this Question and Answer for more detail