# How to calculate the rotation Angle difference between similarity contours

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.

``````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;
}
``````