gpt4 book ai didi

c++ - 轮廓和矩形 OPENcv c++ 之间的交集

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:11:59 33 4
gpt4 key购买 nike

矩形在两点处与完整轮廓相交。我怎样才能找到矩形和等高线轮廓之间的这些交点。

我可以将两个图像加在一起并寻找最大值,但我知道矩形顶点是如何存储的,因为我需要一个用一组点填充的线型 vector

谢谢

最佳答案

如果您确定矩形仅在 2 个点与形状交叉,则可以遍历轮廓点,并检查这些点是否在矩形边界内。

std::vector<cv::Point> shape; // computed with FindContours
cv::Rect myRect; //whatever

const int NUMPOINTS = 2;
int found = 0;
for(std::vector<cv::Point>::iterator it = shape.begin(); it != shapes.end() && found < NUMPOINTS; ++it) {
if (it->y == myRect.y && it->x >= myRect.x && it->x < myRect.x + width)
// that point cross the top line of the rectangle
found++; // you might want to store the point
else if (// ... add the other checks here)

}

关于c++ - 轮廓和矩形 OPENcv c++ 之间的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12746271/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com