# How to track a letter T

I want to use Contour Matching.
I need compute coordinate of center and rotation angle of contour.

Contour Matching is Hu Moment, and are there more algorithm?
For coordinate of center, only use MinAreaRect.
But the rotation angle of MinAreaRect, same time is error, especially when angle is more than 45 degree.
How to do it???
Thanks a lot

edit retag close merge delete

minAreaRect is returning a RotatedRectangle, so if your contour is like a T, then it is not ok IMHO... But if you use it, I think that I had the same problem with the angle, so if the angle is more than 45° then you should add 90° (could you confirm?)

( 2016-01-14 07:03:17 -0600 )edit

Sort by » oldest newest most voted

What you want are the original Moments. They are not location/rotation invariant, and so they contain the information you need. More specifically, they are designed to contain this information.

The centroid would be moments m01 and m10, divided by m00. m10/m00 is X and m01/m00 is Y

The higher order moments contain information about rotation ect. Hopefully this helps.

more

the function 'matchShapes' only can match 1 contour, right?
But if the image of camera have 1000 contour, It will run 1000 times？
It's very slow?

( 2016-01-14 09:23:30 -0600 )edit

matchShapes compares the HuMoments. The comparison is fast, although calculating the HuMoments is not necessarily. Fortunately, you only need to do that once per contour. The most expensive part is probably the Moments calculation, which must be done for HuMoments. And which again, must only be done once per contour.

But to calculate the center and rotation, once matched, you can use the same moments.

( 2016-01-14 15:54:04 -0600 )edit

How to compare the results of matchShapes???
On opencv1, results are 0~1, but I use opencv3, is different.

( 2016-01-15 05:07:29 -0600 )edit

It looks like 0 is a perfect match. So the closer to zero, the better.

You can see the code here: https://github.com/Itseez/opencv/blob...

You can see the exact details of the math, put in exact matches and very wrong matches and see how they would come out.

If you want to save time while running, you can calculate the HuMoments and Moments yourself, and write your own matching function using just the case statement.

( 2016-01-15 07:11:48 -0600 )edit

Official site

GitHub

Wiki

Documentation