title: opencv - Contour Alignment and comparison
body: <p>I have tried to use edge detection to find the contour of images and try to compare the similarity of the contours by matchshape function. However, results are not as good as expected. I think it may be because of the images are not aligned before calculating the similarity. Therefore, I am asking for a way of aligning two contours in opencv. I am thinking of aligning by first finding the smallest bounding box or circle and then find out translation, rotation or resize needed to align those boxes. Then apply those transformation on the contour and test the similarity of them. Does this method work? Is there any method to align images? Thanks for your help. For your reference, attached are two contours going to be tested. They should be very similar but the distance found is quite large. The first two images have larger distance than that between the first and the last one, which seems contradicts with what it looks like (the last one should be the worst). Thanks.<a href="https://i.stack.imgur.com/EX2Ar.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EX2Ar.png" alt="Image 1"></a>
  <a href="https://i.stack.imgur.com/Q1b5b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q1b5b.png" alt="Image 2"></a>
  <a href="https://i.stack.imgur.com/ql9tw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ql9tw.png" alt="Bad Image"></a></p>