【问题标题】:contour plot OpenCV4Android Library等高线图 OpenCV Android 库
【发布时间】:2013-01-29 03:18:43
【问题描述】:

我正在使用 OpenCv4Android 库,并通过示例程序 color-blob-detection。 在此,为了绘制轮廓,他们首先使用表达式对其进行过滤: (轮廓面积>0.1*(最大轮廓面积)

 if (Imgproc.contourArea(contour) > mMinContourArea*maxArea) {
            Core.multiply(contour, new Scalar(4,4), contour);
            mContours.add(contour);

然后,他们对每个过滤后的轮廓使用标量乘法。它的目的是什么?是合并几个小轮廓吗?没明白。请指教!! 第二件事,为什么他们使用乘法因子 Scalar(4,4),为什么不使用其他。

代码:

    Imgproc.pyrDown(rgbaImage, mPyrDownMat);
    Imgproc.pyrDown(mPyrDownMat, mPyrDownMat);

    Imgproc.cvtColor(mPyrDownMat, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL);

    Core.inRange(mHsvMat, mLowerBound, mUpperBound, mMask);
    Imgproc.dilate(mMask, mDilatedMask, new Mat());

    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

    Imgproc.findContours(mDilatedMask, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    // Find max contour area
    double maxArea = 0;
    Iterator<MatOfPoint> each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint wrapper = each.next();
        double area = Imgproc.contourArea(wrapper);
        if (area > maxArea)
            maxArea = area;
    }

    // Filter contours by area and resize to fit the original image size
    mContours.clear();
    each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint contour = each.next();
        if (Imgproc.contourArea(contour) > mMinContourArea*maxArea) {
            Core.multiply(contour, new Scalar(4,4), contour);
            mContours.add(contour);

    Imgproc.drawContours(mRgba, mContours, -1, CONTOUR_COLOR);

【问题讨论】:

    标签: android opencv image-processing contour


    【解决方案1】:

    如果您查看代码,您会发现他们确实首先使用了这个:

    Imgproc.pyrDown(rgbaImage, pyrDownMat); //Divide length and height by 2
    Imgproc.pyrDown(pyrDownMat, pyrDownMat); //Divide length and height by 2
    

    在这些行中,框架长度和高度除以四,这将减少所需的处理时间。 要将轮廓放回原始框架上,他们必须将长度和高度调整为 4,这就是原因,使用了这条线。

    new Scalar(4,4)
    

    我希望我说清楚了;)

    【讨论】:

      【解决方案2】:

      暂时我不能完全回答这个问题,但这是我得到的。

      Core.multiply(contour, new Scalar(4,4), contour);
      

      第一个参数是源矩阵,第二个是乘数,第三个是结果矩阵。如果您考虑到这一点,那么该代码会将源轮廓缩放 4 倍。

      为什么是 4? 这个我不知道,但是通过代码上面的评论 - “调整大小以适应原始图像大小” - 我猜这个想法是做那个拟合,但我看不出你是如何通过将轮廓乘以 4 来实现的。

      【讨论】:

      • 你说的从文档中已经很明显了......但是为了获得所需的 blob,1)为什么他们需要乘以一个标量? 2)当我将其更改为标量(3,3)时,轮廓变小(显然),但被移动了,我不明白为什么!
      • 在您的问题中,您问“是否要合并几个小轮廓?”。我认为情况并非如此,所以这就是我试图澄清这一点的原因。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      相关资源
      最近更新 更多