[英]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.