Android java opencv 2.4 convex convex solution

Open-CV 2.4 Android-Java:

I searched for outlines (MatofPoint list) as follows:

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

and then a convex element (there should be a MatofInt list)

 for (int k=0; k < contours.size(); k++){ Imgproc.convexHull(contours.get(k), hull.get(k)); } 

The graduation housing wants MatofInt, but drawcontours wants MatofPoint. So what to do?

thanks 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); 
+7
source share
2 answers

It seems that the OpenCV Java API is missing another convexHull () signature:

 convexHull(MatOfPoint points, MatOfPoint hull); 

how can you call in C ++.

Until we add it, you need to manually create the body in the MatOfPoint format:

  • use MatOfPoint::toArray() or MatOfPoint::toList() to get contour points
  • use MatOfInt::toArray() or MatOfInt::toList() to get your indexes for the body
  • create a new Point[] or List<Point> with body points only
  • convert it to MatOfPoint via MatOfPoint::fromArray() or MatOfPoint::fromList()
  • call Core.drawContours()
+4
source

we need to clear the hullPointList before adding a list point for the path

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

All Articles