mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-06 03:31:41 +00:00
Address memory leak from draw2dcontourspipe
This commit is contained in:
@@ -2,7 +2,6 @@ package com.chameleonvision.vision.pipeline.pipes;
|
|||||||
|
|
||||||
import com.chameleonvision.vision.camera.CaptureStaticProperties;
|
import com.chameleonvision.vision.camera.CaptureStaticProperties;
|
||||||
import com.chameleonvision.util.Helpers;
|
import com.chameleonvision.util.Helpers;
|
||||||
import com.chameleonvision.vision.image.CaptureProperties;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.opencv.core.Point;
|
import org.opencv.core.Point;
|
||||||
import org.opencv.core.*;
|
import org.opencv.core.*;
|
||||||
@@ -30,6 +29,9 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
|||||||
camProps = captureProps;
|
camProps = captureProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Point[] vertices = new Point[4];
|
||||||
|
private List<MatOfPoint> drawnContours = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Mat, Long> run(Pair<Mat, List<RotatedRect>> input) {
|
public Pair<Mat, Long> run(Pair<Mat, List<RotatedRect>> input) {
|
||||||
long processStartNanos = System.nanoTime();
|
long processStartNanos = System.nanoTime();
|
||||||
@@ -45,18 +47,19 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
|||||||
RotatedRect r = input.getRight().get(i);
|
RotatedRect r = input.getRight().get(i);
|
||||||
if (r == null) continue;
|
if (r == null) continue;
|
||||||
|
|
||||||
List<MatOfPoint> drawnContour = new ArrayList<>();
|
drawnContours.forEach(Mat::release);
|
||||||
Point[] vertices = new Point[4];
|
drawnContours.clear();
|
||||||
|
|
||||||
r.points(vertices);
|
r.points(vertices);
|
||||||
MatOfPoint contour = new MatOfPoint(vertices);
|
MatOfPoint contour = new MatOfPoint(vertices);
|
||||||
drawnContour.add(contour);
|
drawnContours.add(contour);
|
||||||
|
|
||||||
if (settings.showCentroid) {
|
if (settings.showCentroid) {
|
||||||
Imgproc.circle(processBuffer, r.center, 3, Helpers.colorToScalar(settings.centroidColor));
|
Imgproc.circle(processBuffer, r.center, 3, Helpers.colorToScalar(settings.centroidColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.showRotatedBox) {
|
if (settings.showRotatedBox) {
|
||||||
Imgproc.drawContours(processBuffer, drawnContour, 0, Helpers.colorToScalar(settings.rotatedBoxColor), settings.boxOutlineSize);
|
Imgproc.drawContours(processBuffer, drawnContours, 0, Helpers.colorToScalar(settings.rotatedBoxColor), settings.boxOutlineSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.showMaximumBox) {
|
if (settings.showMaximumBox) {
|
||||||
@@ -67,10 +70,10 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (settings.showCrosshair) {
|
if (settings.showCrosshair) {
|
||||||
Point xMax = new Point(camProps.centerX + 10, camProps.centerY);
|
xMax.set(new double[] {camProps.centerX + 10, camProps.centerY});
|
||||||
Point xMin = new Point(camProps.centerX - 10, camProps.centerY);
|
xMin.set(new double[] {camProps.centerX - 10, camProps.centerY});
|
||||||
Point yMax = new Point(camProps.centerX, camProps.centerY + 10);
|
yMax.set(new double[] {camProps.centerX, camProps.centerY + 10});
|
||||||
Point yMin = new Point(camProps.centerX, camProps.centerY - 10);
|
yMin.set(new double[] {camProps.centerX, camProps.centerY - 10});
|
||||||
Imgproc.line(processBuffer, xMax, xMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
Imgproc.line(processBuffer, xMax, xMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||||
Imgproc.line(processBuffer, yMax, yMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
Imgproc.line(processBuffer, yMax, yMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||||
}
|
}
|
||||||
@@ -84,6 +87,10 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
|||||||
long processTime = System.nanoTime() - processStartNanos;
|
long processTime = System.nanoTime() - processStartNanos;
|
||||||
return Pair.of(outputMat, processTime);
|
return Pair.of(outputMat, processTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
|
private Point xMax = new Point(), xMin = new Point(), yMax = new Point(), yMin = new Point();
|
||||||
|
|
||||||
public static class Draw2dContoursSettings {
|
public static class Draw2dContoursSettings {
|
||||||
public boolean showCentroid = false;
|
public boolean showCentroid = false;
|
||||||
public boolean showCrosshair = false;
|
public boolean showCrosshair = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user