Ask Your Question
0

How to track a letter T

asked 2016-01-14 05:48:14 -0600

nistar gravatar image

updated 2020-10-23 09:11:29 -0600

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 flag offensive close merge delete

Comments

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?)

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

1 answer

Sort by » oldest newest most voted
1

answered 2016-01-14 07:06:13 -0600

Tetragramm gravatar image

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.

edit flag offensive delete link more

Comments

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?

nistar gravatar imagenistar ( 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.

Tetragramm gravatar imageTetragramm ( 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.

nistar gravatar imagenistar ( 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.

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

Question Tools

1 follower

Stats

Asked: 2016-01-14 05:48:14 -0600

Seen: 298 times

Last updated: Jan 14 '16