Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Triangle detection - Canny failing on corner

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

Triangle detection - Canny failing on corner

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.pngfile

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

Triangle detection - Canny failing on corner

Hi

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

length(approx) != 3

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

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