本文介绍了Android的Java的OpenCV的2.4凸形轮廓convexdefect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开-CV 2.4的Andr​​oid Java的:

我已经寻找轮廓(MatofPoint列表)是这样的:

  Imgproc.findContours(roi_mat,轮廓,层次结构,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);

    对于(INT J = 0; J< hullInt.toList()的大小(); J ++){
        hullPointList.add(contours.get(K).toList()得到(hullInt.toList()得到(J)));
    }

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

Imgproc.drawContours(MROI,hullPoints,-1,新标量(255,0,0,255),1);
 

解决方案

看起来像OpenCV中的Java API缺少另一个凸形轮廓()签名:

 凸形轮廓(MatOfPoint点,MatOfPoint船体);
 

像它可能在C ++中调用。

虽然我们还没有添加它,你需要创建 MatOfPoint 手动格式为:

  • 使用 MatOfPoint ::的toArray() MatOfPoint ::了ToList()来获得轮廓的分
  • 使用 MatOfInt ::的toArray() MatOfInt ::了ToList()来得到他们的索引船体
  • 创建一个新的点[] 名单,其中;点> 船体的点只有
  • 通过 MatOfPoint :: fromArray() MatOfPoint ::将其转换为 MatOfPoint fromlist里()
  • 呼叫 Core.drawContours()

Open-CV 2.4 Android-Java:

i have searched for contours (list of MatofPoint) like this:

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

and then the convexhull (has to be a list of MatofInt )

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

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

The convexhull wants a MatofInt but the drawcontours wants a MatofPoint.. So what to do?

Thx in advance..


Edit: @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);
解决方案

Looks like OpenCV Java API lacks another convexHull() signature:

convexHull(MatOfPoint points, MatOfPoint hull);

like it's possible to call in C++.

While we haven't added it, you need to create the hull in MatOfPoint format manually:

  • use MatOfPoint::toArray() or MatOfPoint::toList() to get contour's points
  • use MatOfInt::toArray() or MatOfInt::toList() to get their indexes for hull
  • create a new Point[] or List<Point> with hull's points only
  • convert it to MatOfPoint via MatOfPoint::fromArray() or MatOfPoint::fromList()
  • call Core.drawContours()

这篇关于Android的Java的OpenCV的2.4凸形轮廓convexdefect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 07:33