# Comparing Two Contours: Rotation invariant?

I found one approach for estimate the orientation of two contours here , which rotates one contour and checks the distance to the original. I changed the headers to

#include <opencv2/core.hpp>
#include <opencv2/shape.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv_modules.hpp>
#include <iostream>
#include <fstream>
#include <string.h>


and the main to:

int main(int argc, char* argv[])


It may be kind of a stupid question, but first of all i don't know, why the transformation of the contours should improve the result of computeDistance. Is the <cv::shapecontextdistanceextractor> not invariant to rotation and translation, because it does an internal fit?

If this would be the case, my results would be coherent, because I always get 0 as distance (but unfortunately no image as well). Also the result from an other program, where i match rotated contours with cv::shapecontextdistanceextractor> as well as the hausdorff metric seems not to be wrong (small distances, but no exact 0).

edit retag close merge delete

Well, that question specifically asked about orientation, not translation. By removing the translation, it removes a complication and makes the results easier to understand.

( 2017-06-07 16:57:34 -0500 )edit

the cv::shapecontextdistanceextractor IS invariant to rotation and translation, because it does an internal fit.

( 2017-06-07 22:51:35 -0500 )edit

so how can this part of the code work if the extractor is invariant?

    for (int i = 0; i < 8; i++)
{
RotateContour(contours_Trans,contours_Rotated,Angle,ptCCentre);
TestContour= simpleContour(contours_Rotated);
float dis = mysc->computeDistance( QueryContour, TestContour);
if(Angle>=360)
Angle=0.0;
else
Angle+=45.0;

if ( dis<bestDis )
{
bestMatch  = Angle;
bestDis = dis;
}


}

edit: Because if its invariant dist would be independent of the angle - or do I understand something wrong?

( 2017-06-08 00:39:58 -0500 )edit