We are a little new to openCV Java and have encountered a problem.
We are trying to convert this code to Java for Android.
When approaching an approximate pixel, MatOfPoint2f is required, where we have the parameter "approx". Although, when we need to use the same variable in the if statement right after isContourConvex, it requires MatOfPoint. The original code primarily used an ArrayList for approx. We are very confused about this and need a push in the right direction to understand what we should do.
java.util.ArrayList<java.util.ArrayList<Point>>();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(bw.clone(), contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
MatOfPoint2f approx = new MatOfPoint2f();
Mat dst = img.clone();
for (int i = 0; i < contours.size(); i++)
{
MatOfPoint2f contoursMat2 = new MatOfPoint2f( contours.get(i));
Imgproc.approxPolyDP(contoursMat2, approx, Imgproc.arcLength(contoursMat2, true) * 0.02, true);
if (Math.abs(Imgproc.contourArea(contours.get(i))) < 100 || !Imgproc.isContourConvex(approx))
continue;
source
share