在ROI中使用FindContours,将轮廓的坐标错误
Using findContours in a ROI, coordinates of contours wrong
我使用 Mat
的过载运算符在previoulsy set ROI中使用函数 findContours
。轮廓被提取得很好,但是它们的坐标不是全球性的,他们属于ROI。因此,当我想将它们吸引到图像中时,它们都被绘制在定义我的ROI的矩形中。我想我只是想念这里的一些基本。有人有一个主意吗?
这是代码段。
Mat roi(img_grad, inflated_rect);
findContours( roi, canidates, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
for(int i = 0; i < canidates.size(); ++i) {
drawContours(mat, canidates, i, Scalar(0,0,255), 1, CV_AA, hierarchy, 1, Point(0,0));
}
findContours
相对于您的ROI返回坐标。
因此,您应该通过ROI偏移移动所有点(请注意最后一个参数):
for(int i = 0; i < canidates.size(); ++i) {
drawContours(mat, canidates, i, Scalar(0,0,255), 1, CV_AA, hierarchy, 1, inflated_rect.tl());
}
或获得另一个用于绘图的ROI:
for(int i = 0; i < canidates.size(); ++i) {
Mat roi2(mat, inflated_rect);
drawContours(roi2, canidates, i, Scalar(0,0,255), 1, CV_AA, hierarchy, 1, Point(0,0));
}
相关文章:
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- OpenGL 4.3 错误地将第 4 个纹理坐标映射到与第 3 个纹理坐标相同的位置
- 比较两个节点坐标的最佳方法是什么?
- 在 OpenGL 中将笛卡尔世界坐标转换为球面局部坐标
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- 如何在C++中获取坐标?
- 如何将 x.y 坐标的值存储在不同的数组中
- 如何将鼠标坐标转换为"mm"
- 重心坐标并不总是有效(3d)
- 尝试渲染像素坐标时,简单线条渲染失败
- 使用 GTK3 C++获取指针坐标
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 我想制作设置鼠标回调函数,以便在仍然按下鼠标左键时连续传递坐标
- 将鼠标悬停在图片框上时,如何显示带有 x-y 坐标的十字准线光标?
- 跳转到通过输入坐标定义的控制台屏幕位置
- QImage::p ixel 和 QImage::setPixel 坐标超出范围误差
- 如何从 3d 对象文件中获取 3d 坐标
- 在ROI中使用FindContours,将轮廓的坐标错误