Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions modules/mcc/src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,30 @@ mace_center(const std::vector<cv::Point2f> &ps)
return center;
}

void polyanticlockwise(std::vector<cv::Point2f> &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<cv::Point2f> &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
29 changes: 2 additions & 27 deletions modules/mcc/src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,9 @@ void unique(const std::vector<T> &A, std::vector<T> &U)
U.push_back(Tm[i]);
}

template <typename T>
void polyanticlockwise(std::vector<T> &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<cv::Point2f> &points);
void polyclockwise(std::vector<cv::Point2f> &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 <typename T>
void polyclockwise(std::vector<T> &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 <typename T>
std::string ToString(const T &value)
Expand Down