I have a problem with putting my convexity defects on the frame. To calculate them, I modified c++ source and this is what i archived:
mConvexityDefectsMatOfInt4 = new MatOfInt4(); if(contours.size() > 0 && convexHullMatOfInt.rows() > 0) Imgproc.convexityDefects(contours.get(0), convexHullMatOfInt, mConvexityDefectsMatOfInt4); However, the Imgproc.drawContours(...) method requires that convexityDefects passed to it as a parameters will be ArrayList. I don't know how can I make the conversion. I had also similar problem with convex hulls, but I found out a walkaround:
convexHullMatOfInt = new MatOfInt(); convexHullPointArrayList = new ArrayList<Point>(); convexHullMatOfPoint = new MatOfPoint(); convexHullMatOfPointArrayList = new ArrayList<MatOfPoint>(); //Calculate convex hulls if(contours.size() > 0) { Imgproc.convexHull( contours.get(0), convexHullMatOfInt, false ); for(int j=0; j < convexHullMatOfInt.toList().size(); j++) convexHullPointArrayList.add(contours.get(0).toList().get(convexHullMatOfInt.toList().get(j))); convexHullMatOfPoint.fromList(convexHullPointArrayList); convexHullMatOfPointArrayList.add(convexHullMatOfPoint); } Similar solution for convexity defects is not working. Does anyone have an idea on how can I solve the problem?
How to convert from MatOfInt4() to ArrayList() to be able to draw convexity defects?