2012-06-09 45 views
7

開放-CV 2.4的Android的Java:的Android的Java OpenCV的2.4凸形輪廓convexdefect

...我已經尋找輪廓(MatofPoint列表)是這樣的:

Imgproc.findContours(roi_mat, contours, hierarchy, cfg.retMode, cfg.apxMode); 

,然後凸形輪廓(有是MatofInt列表)

for (int k=0; k < contours.size(); k++){ 

    Imgproc.convexHull(contours.get(k), hull.get(k)); 
} 

的凸形輪廓想要一個MatofInt但日e drawcontours想要一個MatofPoint ..那麼該怎麼做?

THX提前..


編輯:@ OpenCV4Android

for (int k=0; k < contours.size(); k++){ 
    Imgproc.convexHull(contours.get(k), hullInt); 

    for(int j=0; j < hullInt.toList().size(); j++){ 
     hullPointList.add(contours.get(k).toList().get(hullInt.toList().get(j))); 
    } 

    hullPointMat.fromList(hullPointList); 
    hullPoints.add(hullPointMat); 
} 

Imgproc.drawContours(mROI, hullPoints, -1, new Scalar(255,0,0, 255), 1); 

回答

4

貌似OpenCV的Java API的缺少另一個凸形輪廓()簽名:

convexHull(MatOfPoint points, MatOfPoint hull); 

像可以用C++調用。

雖然我們還沒有添加它,你需要在手動格式創建船體 MatOfPoint:

  • 使用MatOfPoint::toArray()MatOfPoint::toList()得到輪廓的點
  • 使用MatOfInt::toArray()MatOfInt::toList()得到他們的船體索引
  • 創建一個新的Point[]List<Point>與船體只有
  • 它通過MatOfPoint::fromArray()MatOfPoint::fromList()
  • 呼叫Core.drawContours()
+0

確定THX。我會嘗試,讓你知道.. – ddd

+0

以及我已經嘗試過這樣(編輯問題): 我不知道如果它完全正確,因爲我沒有得到好的結果..大部分時間有很多紅色的凸包線穿過img .. – ddd

+0

或者是因爲findcontour(我試過一個canny和/或門限和gauss過濾器在findcontour之前) – ddd

0

轉換爲MatOfPoint我們需要之前添加列表點明確hullPointList的輪廓

hullPointList .clear(); 
for(int j=0; j < hullInt.toList().size(); j++){ 
     hullPointList.add(contours.get(k).toList().get(hullInt.toList().get(j))); 
    }