Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edge detection using OpenCV (Canny)

I'm trying to detect rectangles using OpenCV. However, sometimes this is getting pretty difficult after running the Canny method, because two of the edges are usually being erased out. I've tried many different sets of thresholds and blurring it before applying Canny, but I haven't got major positive results yet. Currently, I'm not blurring the image, so this is pretty much what I'm doing:

Mat imgSource = Highgui.imread(filepath);
Imgproc.Canny(imgSource, imgSource, 300, 600, 5, true); 

Example:

original http://imagizer.imageshack.us/a/img822/8776/27i9j.jpg Canny http://imagizer.imageshack.us/a/img841/9868/wkc95.jpg

Then, I'm trying OpenCV's findContours method to detect the rectangle, it works 80% of the time, how can I improve it?

like image 371
Arthur Ferreira Avatar asked Jun 12 '14 00:06

Arthur Ferreira


People also ask

What is canny edge detection OpenCV?

The Canny edge detector is a multi-step algorithm used to detect a wide range of edges in images. The algorithm itself was introduced by John F. Canny in his 1986 paper, A Computational Approach to Edge Detection.

How does OpenCV edge detection work?

Edge detection is an image-processing technique, which is used to identify the boundaries (edges) of objects, or regions within an image. Edges are among the most important features associated with images. We come to know of the underlying structure of an image through its edges.

What is used to OpenCV is used to detect edges of the image?

In this article, the popular canny edge detection algorithm is used to detect a wide range of edges in images. OpenCV has in-built function cv2. Canny() which takes our input image as first argument and its aperture size(min value and max value) as last two arguments.


2 Answers

Try with different threshold value, in this case you will get better result when using lower threshold values, like 10,100.

blur(src,src,Size(3,3));
cvtColor(src,tmp,CV_BGR2GRAY);
Canny( src, thr, 10, 100, 3 );

Or in another way you will get the contour images by applying threshold like,

threshold(tmp,thr,50,255,THRESH_BINARY_INV);
like image 123
Haris Avatar answered Oct 07 '22 01:10

Haris


the problem here is the image compression JPEG file type probably.
try converting image to monochrome since you only have Black/white image and edit the threshold value.
this should eliminate the noise around the edges of the lines. then canny can be applied with any values.

like image 28
Murad Dasi Avatar answered Oct 07 '22 01:10

Murad Dasi