7

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);
4

2 に答える 2

4

OpenCV Java API には、別の凸包 () シグネチャが欠けているようです。

convexHull(MatOfPoint points, MatOfPoint hull);

C++で呼び出すことができるように。

まだ追加していませんが、ハルMatOfPoint形式で手動で作成する必要があります。

  • MatOfPoint::toArray()またはを使用MatOfPoint::toList()して輪郭の点を取得します
  • 船体のインデックスを使用MatOfInt::toArray()または取得するMatOfInt::toList()
  • 新しいものを作成するPoint[]List<Point>、ハルのポイントのみを使用して
  • またはMatOfPoint経由で変換しますMatOfPoint::fromArray()MatOfPoint::fromList()
  • 電話Core.drawContours()
于 2012-06-09T15:35:52.097 に答える
0

等高線のリスト ポイントを追加する前に、hullPointList をクリアする必要があります。

hullPointList .clear();
for(int j=0; j < hullInt.toList().size(); j++){
        hullPointList.add(contours.get(k).toList().get(hullInt.toList().get(j)));
    }
于 2013-06-28T07:29:44.897 に答える