Ask Your Question
0

Triangle detection - Canny failing on corner [closed]

asked 2016-01-08 17:29:09 -0600

epatton gravatar image

updated 2020-05-26 07:12:48 -0600

supra56 gravatar image

Hi

I'm trying to detect a triangle however approxPolyDP fails because:

length(approx) != 3
approx = cv2.approxPolyDP(.....)

I think its because the Canny algortihm somehow cannot find lower right virtex edge. (see image below).

The input image (zoomed using Imagj)

image description

and Imagej pixel inspection tool output of lower right virtexd

image description

Here is the Canny output. I've tried numerous thresholds and get the same opening in the lower RHS virtex.

image description

My code

>>> import cv2
>>> import sys
>>> import numpy as np
>>> filename = 'diffGr.png'
>>> img = cv2.imread(filename,cv2.IMREAD_GRAYSCALE)
>>> minVal = 20
>>> maxVal = 200
>>> edges = cv2.Canny(img,minVal,maxVal)
>>> cv2.namedWindow('Edge image')
>>> cv2.imshow('Edge image',edges)
>>> cv2.waitKey(0)

My input file

C:\fakepath\diffGr.png

Any info on understanding why Canny fails would be appreciated. If this is expected, should I use a different edge detection method?

Cheers

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by supra56
close date 2020-05-26 07:11:17.346789

Comments

1

Why not Threshold and then find canny edges?

Balaji R gravatar imageBalaji R ( 2016-01-09 01:30:55 -0600 )edit

That worked! Thanks

epatton gravatar imageepatton ( 2016-01-11 13:08:17 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-11 13:15:58 -0600

epatton gravatar image

updated 2016-01-11 14:01:36 -0600

Thanks to Balaji, Canny now works

I'd still like to understand why Canny does not find the edge on the lower right virtex but has no issue with the lower left. I guess I could try flipping the image in the vertical axis. Canny should fail on the lower left then if its a data dependent issue.

image description

thresh = 50
maxValue = 255
th, dst = cv2.threshold(img, thresh, maxValue, cv2.THRESH_BINARY);
maxVal = 200
edges1 = cv2.Canny(dst,minVal,maxVal)
cv2.imshow('Edge image after thresholding image',edges) 
cv2.waitKey(0)
edit flag offensive delete link more

Comments

OpenCL version of Canny contains bug more than 1 year. Try to compare OpenCL and non-OpenCL (use cv::ocl::setUseOpenCL(false) ) results.

Vit gravatar imageVit ( 2016-01-11 17:22:04 -0600 )edit

Thanks for pointing that out. I tried to set ocl to false but no luck.

>>> cv2.__version__
'3.0.0'
>>> print(cv2.ocl.haveOpenCL())
True
>>> cv2.ocl.setUseOpenCL(False)
>>> print(cv2.ocl.haveOpenCL())
True
>>>

It looks like the issue is yet to be resolved according to the link in this post. http://stackoverflow.com/questions/31...

epatton gravatar imageepatton ( 2016-01-12 20:56:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-08 17:29:09 -0600

Seen: 1,261 times

Last updated: May 26 '20