Point2f calcCenterOfMass(vector pointCloud) { Point2f COM = Point2f(0, 0); if (!pointCloud.empty()) { for (auto &point : pointCloud) COM = COM + point; COM = COM / (float) pointCloud.size(); } return COM; } Point2f normalize(Point2f point){ float magnitude = sqrt(point.x*point.x+point.y*point.y); return point/magnitude; } float calcRotation(vector matched1, vector matched2) { //make keypoints to Points vector pointCloudOne; vector pointCloudTwo; for (auto &match : matched1) pointCloudOne.push_back(match.pt); for (auto &match : matched2) pointCloudTwo.push_back(match.pt); //calc centerofmasses Point2f COM1 = calcCenterOfMass(pointCloudOne); Point2f COM2 = calcCenterOfMass(pointCloudTwo); //move second pointcloud to first Point2f difference = COM1 - COM2; for(auto &point: pointCloudTwo) point += difference; float angle=0; for(int i=0; i