2012-06-09 44 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))); 
    }