[英]Finding extreme points in contours with OpenCV C++
I have tried to implement this code , but I have a trouble when I want to determine the most extreme point of the contour follow this tutorial. 我试图实现这个代码 ,但是当我想确定轮廓的最极端点时,我遇到了麻烦。
# determine the most extreme points along the contour
extLeft = tuple(c[c[:, :, 0].argmin()][0])
extRight = tuple(c[c[:, :, 0].argmax()][0])
extTop = tuple(c[c[:, :, 1].argmin()][0])
extBot = tuple(c[c[:, :, 1].argmax()][0])
Can anyone help me to solve this problem? 任何人都可以帮我解决这个问题吗?
Starting from a std::vector<cv::Point>
, you can use std::max_element
and std::min_element
with an appropriate comparator, that works on x
coordinates to find left and right points, and works on y
coordinates to find top and bottom points: 从
std::vector<cv::Point>
,你可以使用std::max_element
和std::min_element
和一个适当的比较器,它可以在x
坐标上找到左边和右边的点,并在y
坐标上工作以查找顶点和底点:
// Your points
vector<Point> pts;
...
Point extLeft = *min_element(pts.begin(), pts.end(),
[](const Point& lhs, const Point& rhs) {
return lhs.x < rhs.x;
});
Point extRight = *max_element(pts.begin(), pts.end(),
[](const Point& lhs, const Point& rhs) {
return lhs.x < rhs.x;
});
Point extTop = *min_element(pts.begin(), pts.end(),
[](const Point& lhs, const Point& rhs) {
return lhs.y < rhs.y;
});
Point extBot = *max_element(pts.begin(), pts.end(),
[](const Point& lhs, const Point& rhs) {
return lhs.y < rhs.y;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.