簡體   English   中英

android java opencv 2.4 convexhull convexdefect

[英]android java opencv 2.4 convexhull convexdefect

Open-CV 2.4 Android-Java:

我搜索了等高線(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,但是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);

看起來OpenCV Java API缺少另一個convexHull()簽名:

convexHull(MatOfPoint points, MatOfPoint hull);

喜歡用C ++調用它。

雖然我們還沒有添加它,但您需要手動創建MatOfPoint格式的外殼

  • 使用MatOfPoint::toArray()MatOfPoint::toList()來獲取輪廓點
  • 使用MatOfInt::toArray()MatOfInt::toList()來獲取船體的索引
  • 僅使用船體點創建新的Point[]List<Point>
  • 通過MatOfPoint::fromArray()MatOfPoint::fromList()將其轉換為MatOfPoint
  • 調用Core.drawContours()

在為輪廓添加列表點之前,我們需要清除hullPointList

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM