- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个要绘制的轮廓列表。其中一些轮廓自相交。
当我想用 OpenCV 绘制它们时,我只需使用 cv::drawContours
函数。
但是,这种行为很奇怪。
这里引用官方documentation
C++: void drawContours(InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar& color, int thickness=1, int lineType=8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point() )
Parameters:
contourIdx – Parameter indicating a contour to draw. If it is negative, all the contours are drawn.
因此,根据文档,如果我想绘制我所有的区域,并用黑色填充,我只需要做:
cv::drawContours(this->mask.raw,
this->areas, -1,
cv::Scalar(0,0,0),
cv::FILLED);
但是,这给了我以下输出:
在这里,我们可以清楚地看到我所有的区域都没有填充黑色。
但是如果我遍历我的区域列表并为每个区域调用 cv::drawContours
:
unsigned int i = 0;
for (const auto& area : this->areas)
cv::drawContours(this->mask.raw,
this->areas, i++,
cv::Scalar(0,0,0),
cv::FILLED);
我得到了与第一个完全不同的好输出:
我是否遗漏了文档中的某些内容?谁能给我解释一下 cv::drawContours
的行为,以及对所有区域调用它和每次对每个区域调用它有什么不同?
最佳答案
我认为,当您将 contourIdx
作为 Negative 传递时,我认为 drawContour
函数只是绘制轮廓而不填充,正如您用 CV_FILLED
指示的那样.通过显式循环遍历每个轮廓,您将获得所得到的结果。
关于c++ - OpenCV drawContours 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31613672/
我有以下代码在 OpenCV 3.4.1 上运行良好,但现在不能在 OpenCV 4.1.0 上运行并给出错误。我不知道如何使代码适应新版本,你能帮我吗?非常感谢 def ImageProcessin
我从二值图像中过滤小 Blob (面积小于阈值的轮廓)。掩码是二值图像。 如果我注释行 drawContours(mask, contours, -1, Scalar(255), CV_FILLED
我正在尝试确定动脉的宽度,并制定了一个非常粗略的程序来验证 drawContours 是否合适。我的问题是轮廓仅打印黑色或白色线条,而不是我尝试使用的彩色线条。我不确定我正在绘制的 img 是否仅限于
在我的 Android 应用程序中,我从图库中获取了一张位图图像,内容如下 Bitmap bitm = getMyImage("Thanks!"); 我有一个名为 mat 的 Mat,声明如下: Ma
我想用 OpenCV drawContours 函数绘制自定义点序列。 我的代码: std::vector > contours; std::vector contour1; contour1.pus
我正在研究在 opencv python 中查找和绘制轮廓的示例。但是当我运行代码时,我只看到一个没有绘制轮廓的黑色窗口。我不知道我哪里错了。代码是: import numpy as np impor
我正在尝试使用 OpenCV 中的 cv2.drawContours 函数显示填充轮廓。我已经根据 Canny 检测得出的边缘图像开发了一个轮廓列表,并且正在为层次结构定义启用 RETR_EXTERN
我有一个要绘制的轮廓列表。其中一些轮廓自相交。 当我想用 OpenCV 绘制它们时,我只需使用 cv::drawContours 函数。 但是,这种行为很奇怪。 这里引用官方documentation
我遵循了 this page 上的教程但是当行 cv2.drawContours(im,contours,-1,(0,255,0),3) 被执行时,似乎什么也没有发生。我期待看到带有绿色轮廓的 sta
我正在尝试在 Xamarin 上开发移动应用程序。首先,我正在为 Android 设备做这件事。我希望 Oncamera 功能能够自动检测轮廓并测量物体的大小。作为主要步骤,我正在尝试实时检测轮廓。阅
需要堆栈溢出的强大帮助。实际上,我开发的应用程序必须通过 OCR(我正在使用 tesseract)文档进行分析,并提取我可以从中提取的所有文本。这是图像类型的示例: Image including t
我正在尝试从图像中绘制轮廓。我从我的网络摄像头得到了一个框架并提取了它的轮廓。然后,我按区域过滤它们,并调用 drawContours() 来显示它们。问题是当我尝试绘制过滤后的轮廓时...如果我绘制
我是在 Visual Studio 上使用 OpenCV 的新手,最近我重新安装了我的 VS2012 以使其使用 OpenCV 2.4.2 工作。 我正在尝试通过鼠标单击顶点并将它们推送到 CvSeq
我有一个 python 代码,我正在将它移植到 c++。我在 OpenCV c++ 中遇到了 drawContours 函数的奇怪问题。 self.contours[i] = cv2.convexHu
这个问题在这里已经有了答案: Contour shows dots rather than a curve when retrieving it from the list, but shows t
我有以下图像,其中包含无人机捕获的汽车和空 parking 位。我想检测空的公园空间并绘制一个看起来像预期图像的框。 这是我的代码: import cv2 import numpy as np fro
我有一个包含 4 个点的 vector : vector > data(4); data[0].push_back(Point(0,0)); data[1].push_back(Point(0,120
我试图找到最大的正方形并将其绘制在原始图像上。 当我打电话 drawContours(input,(screenCnt),-1,Scalar(255,0,0),3); 出现以下错误: E/cv::er
我正在尝试绘制最大物体的轮廓。 首先,我将展示一张绘制所有轮廓的图像: 为了找到最大的对象,我使用了这段代码: maxsize = 0 best = 0 count = 0 for cnt in
按照@Silencer 的建议,我使用了他发布的代码 here围绕我图像中的数字绘制轮廓。在某些时候,处理像 0,6,8,9 这样的数字时,我看到它们的内部轮廓(圆圈)也被填充了。我怎样才能防止这种情
我是一名优秀的程序员,十分优秀!