【问题标题】:Using OpenCV, how to draw contours INSIDE the edges of detected shape/blob?使用 OpenCV,如何在检测到的形状/斑点的边缘内绘制轮廓?
【发布时间】:2017-11-29 17:31:04
【问题描述】:

以下是使用 OpenCV4Android 在 Android 应用中检测到的蓝色斑点的图像。我使用Core.inRange()Imgproc.findContours() 方法找到轮廓,并使用Imgproc.drawContours() 绘制它们:

Mat mask = new Mat();
Core.inRange(rgbaMat, lowerThreshold, upperThreshold, mask);
...
contours = new ArrayList<>();
Imgproc.findContours(dilatedMat, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
...
for ( int contourIdx=0; contourIdx < contours.size(); contourIdx++ ) { 
    Imgproc.drawContours ( rgbaMat, contours, contourIdx, new Scalar(0, 255, 0), 1);
}

轮廓(浅绿色边界)在检测到的形状之外。

因此,如您所见,它还包括检测到的蓝色斑点周围的一些白色区域。我希望轮廓边界位于蓝色斑点/形状的边缘内。

我该怎么做?

【问题讨论】:

    标签: android opencv opencv3.0 opencv4android


    【解决方案1】:

    我可以在您的代码中看到您在变量“dilatedMat”(第 5 行)上应用了“findContours”。我假设您在“rgbaMat”(第 3 行某处)上应用了“扩张”过滤器。但是如果你想让轮廓在里面,你应该应用 "erode" 而不是 "dilate"

    【讨论】:

      【解决方案2】:

      您可以在drawContour厚度参数中使用一些负值,这将在检测到的对象内绘制轮廓。

      Imgproc.drawContours ( rgbaMat, contours, contourIdx, new Scalar(0, 255, 0), -1);
      

      【讨论】:

        猜你喜欢
        • 2020-09-22
        • 2014-05-21
        • 2013-06-16
        • 2021-09-07
        • 1970-01-01
        • 2013-12-29
        • 1970-01-01
        • 1970-01-01
        • 2017-07-21
        相关资源
        最近更新 更多