Ask Your Question
1

Recognize basic shapes in binarized image

asked 2013-06-06 19:34:24 -0500

Michał Rus gravatar image

How can I recognize some basic (usually rotated) shapes:

  • circle,
  • "empty" circle,
  • cross,
  • empty triangle,

using OpenCV? What's the most straightforward way? It would be nice if the user could "define" his own shapes somehow (load a template image, possibly).

I'd like to map each recognized shape to its type (circle, triangle etc.) and a position of its center. (And its rotation if possible).

For circles HoughCircles could be used (there's no rotation in this case, too). But what about the others? Template matching doesn't support rotation and scaling, right?...

Here's the input:

empty triangle, empty circle, circles

empty triangle, empty circle, cross

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2013-06-07 04:02:01 -0500

Ben gravatar image

Generic shape recognition is a harder task and probably needs some training. If your shape set is limited (like in your images), it is easier to write a special detection algorithm for every shape.

For example: - distinguish shapes with a hole (empty circle, triangle) from filled shapes (filled circle, cross) using findContours()

  • use houghCircles() on your contours to find out, if it's a circle. If it's not, it's a cross or a triangle

You can also play around with HuMoments()

edit flag offensive delete link more

Comments

Thanks for the suggestions. It occurs matchShapes with "normal" moments (and with template contours) does the trick.

Michał Rus gravatar imageMichał Rus ( 2013-06-07 12:41:30 -0500 )edit
2

answered 2013-06-07 06:39:33 -0500

updated 2013-06-07 06:43:39 -0500

You can also look the hierarchy of the contours.

If one contour is inside of another:

  1. It could be an empty circle
  2. It could be an empty triangle

If it isn't inside:

  1. It could be a circle
  2. It could a cross

Then you can also use approxPolyDP (approximate a curve or a polygon with another curve/polygon with less vertices) to distinguish between the two options.

edit flag offensive delete link more

Comments

Thanks for approxPolyDP suggestion. :) I used matchShapes using some template images.

Michał Rus gravatar imageMichał Rus ( 2013-06-07 12:38:56 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2013-06-06 19:34:24 -0500

Seen: 1,485 times

Last updated: Jun 07 '13