Loop Matching - Loop Offset

I found outlines on two images with the same object, and I want to find the offset and rotation of this object. I tried with the rotating bounding rectangles of these contours, and then its corners and center points, but the turns of the bounding rectangles do not indicate the correct rotation of the contour, because they are the same for angles a + 0, a + 90, a + 180, etc. degrees. Is there any other good way to find the rotation and offset of the contours? Maybe some use a convex hull, convex defects? I read in Learning OpenCv about contour matching, but that didn't help. Can someone give an example?

// edit: Maybe there is some way to use something similar to Freeman chains? But at the moment I can not calculate the algorithm. Creating a chain with angles between a point in a sequence, and then checking if the sequence matches, does not work well ...

+7
source share
1 answer

If the object has convexity defects, you can select one defect, make a vector from the center of gravity of the first contour to the center of gravity of this defect. Then you can check for defects in the second circuit and match the one you used before. Take the vector from the center of gravity of the contour to the center of gravity of the matching defect.

From this you get 2 segments (vectors), from which you can get the offset and rotation.

+3
source

All Articles