avoid creating new mats in group contors pipe

This commit is contained in:
Matt
2020-01-02 12:25:13 -08:00
parent 23796184e0
commit 113ec3c217

View File

@@ -94,10 +94,14 @@ public class GroupContoursPipe implements Pipe<List<MatOfPoint>, List<StandardCV
Pair.of(Imgproc.boundingRect(firstContour),
Imgproc.boundingRect(secondContour));
target.leftRightRotatedRect =
Pair.of(Imgproc.minAreaRect(new MatOfPoint2f(firstContour.toArray())),
Imgproc.minAreaRect(new MatOfPoint2f(secondContour.toArray())));
tempRectMat.fromArray(firstContour.toArray());
var minAreaRect1 = Imgproc.minAreaRect(tempRectMat);
tempRectMat.fromArray(secondContour.toArray());
var minAreaRect2 = Imgproc.minAreaRect(tempRectMat);
target.leftRightRotatedRect =
Pair.of(minAreaRect1, minAreaRect2);
groupedContours.add(target);
}
} catch (IndexOutOfBoundsException e) {
@@ -113,6 +117,8 @@ public class GroupContoursPipe implements Pipe<List<MatOfPoint>, List<StandardCV
return Pair.of(groupedContours, processTime);
}
MatOfPoint2f tempRectMat = new MatOfPoint2f();
private static double calcMomentsX(MatOfPoint c) {
Moments m = Imgproc.moments(c);
return (m.get_m10() / m.get_m00());