2013-02-13 148 views
2

我使用OpenCv4Android庫,並通過示例程序color-blob-detection。 在此,畫輪廓,它們首先與表達篩選它: (輪廓的面積> 0.1 *(最大輪廓的後,他們利用標量乘法的每個經濾波的區域)輪廓圖OpenCV4Android庫

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

然後輪廓。?作用是什麼?它是合併幾個小輪廓?沒得到的想法。PLZ開導! 第二件事情,爲什麼他們用倍增因數標量(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); 

回答

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) 

我希望我清楚;)

0

暫時我不能完全回答這個問題,但這裏是我得到的。

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

第一個參數是源矩陣,第二個參數是乘法因子,第三個參數是結果矩陣。如果你有這個想法,那麼這個代碼就是將源輪廓縮放4倍。

爲什麼4?這我不知道,但通過上面的代碼註釋 - 「調整大小,以適應原始圖像大小」 - 我想這個想法是做適合,但我不知道你是如何實現的,通過乘以輪廓4.

+0

熱點問題研究ü說已經明顯從文件...但要獲得所需的BLOB,1)爲什麼他們需要乘以WID標? 2)當我將它改爲標量(3,3)時,輪廓變得很小(明顯),但是移動了,我不明白爲什麼! – sumit 2013-02-14 13:05:50

+0

在你的問題中,你問「是否合併幾個小輪廓?」。我認爲情況並非如此,所以我試圖澄清這一點。 – 2013-02-14 13:38:50