diff --git a/modules/mcc/src/common.cpp b/modules/mcc/src/common.cpp index 71cba1e8bc..1f44273202 100644 --- a/modules/mcc/src/common.cpp +++ b/modules/mcc/src/common.cpp @@ -86,5 +86,30 @@ mace_center(const std::vector &ps) return center; } +void polyanticlockwise(std::vector &points) +{ + // Sort the points in anti-clockwise order + // Trace a line between the first and second point. + // If the third point is at the right side, then the points are anti-clockwise + cv::Point2f v1 = points[1] - points[0]; + cv::Point2f v2 = points[2] - points[0]; + + //if the third point is in the left side, then sort in anti-clockwise order + if ((v1.x * v2.y) - (v1.y * v2.x) < 0.0) + std::swap(points[1], points[3]); +} +void polyclockwise(std::vector &points) +{ + // Sort the points in clockwise order + // Trace a line between the first and second point. + // If the third point is at the right side, then the points are clockwise + cv::Point2f v1 = points[1] - points[0]; + cv::Point2f v2 = points[2] - points[0]; + + //if the third point is in the left side, then sort in clockwise order + if ((v1.x * v2.y) - (v1.y * v2.x) > 0.0) + std::swap(points[1], points[3]); +} + } // namespace mcc } // namespace cv diff --git a/modules/mcc/src/common.hpp b/modules/mcc/src/common.hpp index aa4c383f55..998f8a4c51 100644 --- a/modules/mcc/src/common.hpp +++ b/modules/mcc/src/common.hpp @@ -73,34 +73,9 @@ void unique(const std::vector &A, std::vector &U) U.push_back(Tm[i]); } -template -void polyanticlockwise(std::vector &points) -{ - // Sort the points in anti-clockwise order - // Trace a line between the first and second point. - // If the third point is at the right side, then the points are anti-clockwise - cv::Point v1 = points[1] - points[0]; - cv::Point v2 = points[2] - points[0]; - - double o = (v1.x * v2.y) - (v1.y * v2.x); +void polyanticlockwise(std::vector &points); +void polyclockwise(std::vector &points); - if (o < 0.0) //if the third point is in the left side, then sort in anti-clockwise order - std::swap(points[1], points[3]); -} -template -void polyclockwise(std::vector &points) -{ - // Sort the points in clockwise order - // Trace a line between the first and second point. - // If the third point is at the right side, then the points are clockwise - cv::Point v1 = points[1] - points[0]; - cv::Point v2 = points[2] - points[0]; - - double o = (v1.x * v2.y) - (v1.y * v2.x); - - if (o > 0.0) //if the third point is in the left side, then sort in clockwise order - std::swap(points[1], points[3]); -} // Does lexical cast of the input argument to string template std::string ToString(const T &value)