# How to calculate the rotation Angle difference between similarity contours

**URL:** <https://forum.opencv.org/t/how-to-calculate-the-rotation-angle-difference-between-similarity-contours/14320>\
**Category:** C++\
**Tags:** imgproc\
**Created:** [August 22, 2023, 7:47am UTC](https://forum.opencv.org/t/how-to-calculate-the-rotation-angle-difference-between-similarity-contours/14320 "2023-08-22T07:47:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://forum.opencv.org/u/abc)\
**Post date:** [August 22, 2023, 7:47am UTC](https://forum.opencv.org/t/how-to-calculate-the-rotation-angle-difference-between-similarity-contours/14320/1 "2023-08-22T07:47:16Z")

</div>

[https://i.stack.imgur.com/E5Vbj.png](https://i.stack.imgur.com/E5Vbj.png). After obtaining the contour data of the picture and the similarity value between the contours, At present not found the method to calculate the rotation Angle difference between similarity contours.

```auto
int main(int argc,char* argv[])
{
    cout<< "params count :"<<argc<<endl;
    cout<< "params value are :";
    for (int i = 0; i < argc; i++) {
        printf(" [%d]: %s",i,argv[i]);
    }

    if (argc > 1){

        Mat src1 = imread(argv[1]);
        imshow(" src1 ",src1);
        cout<<" src1 channels: "<<src1.channels()<<endl;
       

        Mat grayImage;
        if(src1.channels() > 1){
            cvtColor(src1,grayImage,COLOR_BGR2GRAY);
        }else {
            grayImage = src1;
        }

        Mat threshodImage1;
        threshold(grayImage, threshodImage1, 128, 255, THRESH_BINARY|THRESH_OTSU); // | 

        vector<Vec4i> hierarchy;
        vector<vector<Point> > contours;

        findContours(threshodImage1,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);
        cout<< " contours size :" << contours.size() <<endl;

        RotatedRect rRect;
        Moments shapeMoments;
        double shapeHumoments[7];
        Point centerofmass;

        RotatedRect _minAreaRect;

        Mat resImage = Mat::zeros(threshodImage1.size(),CV_8UC3);
        for(size_t i=0; i<contours.size(); i++){

            double area = contourArea(contours[i]);
            shapeMoments = moments(contours[i]);
            HuMoments(shapeMoments,shapeHumoments);
            rRect = cv::minAreaRect(contours[i]);

            centerofmass.x = (shapeMoments.m10 / shapeMoments.m00);
            centerofmass.y = (shapeMoments.m01 / shapeMoments.m00);

             for (size_t j = i+1; j< contours.size(); j++){
                 double match = matchShapes(contours[i],contours[j],1,0.0);
                 cout << i+1 << " VS " << j+1 << " match:" <<match << endl ;
             }

        }

        imshow("resImage",resImage);
        waitKey(1000);

    }
   
    return 0;
}

```
