Contours matching - finding contours displacement I found contours on two images with same object and I want to find displacement and rotation of this object. I've tried with rotated bounding boxes of this contours and then its angles and center points but rotations of bounding boxes don't tell about contour rotation correctly because it's the same for angles a+0, a+90, a+180 etc. degrees. Is it any other good way to find rotation and displacement of contours? Maybe some use of convex hull, convexity defects? I've read in Learning OpenCv about matching contours but it hasn't helped. Could someone give some example?

Examples:






I want to detect for example pink square, and in the second case pen. Other examples could be squares with some holes, stars etc. As I said I want to make some uniwersal thing. Any suggestions are appreciated because I want to test as many methods as it's possible.
Do you have to worry about a difference in scale between contours?  If not than you can simply find the centroid of each contour, and compute displacement by subtracting one from the other.  Then you can calculate the principal axes of the contours, and find the rotation angle between them.

If scaling is involved, then you can calculate the scale factor by taking the ratio of the corresponding principal axes.