Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect triangles, ellipses and rectangles from an image

I am trying to detect the regions of traffic signs. Using OpenCV, my approach is as follows:

The color image:

enter image description here

Using the TanTriggs Preprocessing get rid of the illumination variances:

enter image description here

Equalize histogram:

enter image description here

And binarize (Cv2.Threshold(blobs, blobs, 127, 255, ThresholdTypes.BinaryInv):

enter image description here

Iterate each blob using ConnectedComponents and get the mean color value using the blob as mask. If it is a red color then it may be a red sign.

Then get contours of this blob using FindContours.

Simplify the contours using ApproxPolyDP and check the points of each contour:

  • If 3 points then triangle shape is acceptable --> candidate for triangle sign
  • If 4 points then shape is acceptable --> candidate
  • If more than 4 points, BBox dimensions are acceptable and most of the points are on the ellipse fitted (FitEllipse) --> candidate

This approach works for the separated blobs in the binary image, like the circular 100km sign in my example. However if there is a connection to the outside objects, like the triangle left bottom part in the binary image, it fails.

enter image description here

Because, the mean value of this blob is far from red!

Using Erosion helps in some cases, however makes it worse in many of the other images.

Using different threshold values for the binarization also works for some, but fails on many; like the erosion.

Using HoughCircle is just very slow and I couldn't manage to get good results playing with the parameters.

I have tried using matchShapes but couldn't get good results.

Can anybody show me another way the achieve what I want (with a reasonable computational time)?

Any information, or code in any language is wellcome.

Edit: Using circularity measure (C=P^2/4πA) or the approach I have described above, triangle and ellips shapes can be found when they are separated. However when the contour is like this for example: enter image description here

I could not find a robust way to extract the triangle piece. If I could, I would check the mean color, and decide if its a red sign candidate.

like image 471
Koray Avatar asked Feb 19 '26 21:02

Koray


1 Answers

Sorry, I don't have the kudos to comment, but can't you use the red colour?

import common
myshow = common.myshow

img = cv2.imread("ms0QB.png")
grey = np.zeros(img.shape[:2],np.uint8)
hsv = cv2.cvtColor(img,cv2.COLOR_mask = np.logical_or(hsv[:,:,0]>160,hsv[:,:,0]<10 )
grey[mask] = 255
cv2.imshow("160<hue<182",grey)
cv2.waitKey()
like image 193
Haydon Berrow Avatar answered Feb 27 '26 09:02

Haydon Berrow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!