Question

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

Was it helpful?

Solution

You are right that regular template matching are not rotation, scale invariant. Take a look at OpenCV's matchShapes. Internally, it uses HuMoments. You will need to use findContours to find each individual object. Now once you have done this, you will probably find matchShapes couldn't distinguish Circle from Ring. A simple way to solve this is to use the hierarchy structure from findContours. If there is a hole (large enough) inside a Circle, that's probably a Ring.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top