Arthur Ferreira
Arthur Ferreira

Reputation: 321

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?

Upvotes: 10

Views: 23494

Answers (2)

Murad Dasi
Murad Dasi

Reputation: 31

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.

Upvotes: 2

Haris
Haris

Reputation: 14043

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);

Upvotes: 8

Related Questions