Comparing Two Contours: Rotation invariant?

asked 2017-06-07 13:45:36 -0500

JoeBroesel gravatar image

updated 2017-06-07 14:07:49 -0500

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

Comments

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

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

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

berak gravatar imageberak ( 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?

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