mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-01 02:41:42 +00:00
Added crosshair pipe
This commit is contained in:
@@ -29,6 +29,8 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
|||||||
private Collect2dTargetsPipe collect2dTargetsPipe;
|
private Collect2dTargetsPipe collect2dTargetsPipe;
|
||||||
private Draw2dContoursPipe.Draw2dContoursSettings draw2dContoursSettings;
|
private Draw2dContoursPipe.Draw2dContoursSettings draw2dContoursSettings;
|
||||||
private Draw2dContoursPipe draw2dContoursPipe;
|
private Draw2dContoursPipe draw2dContoursPipe;
|
||||||
|
private Draw2dCrosshairPipe draw2dCrosshairPipe;
|
||||||
|
private Draw2dCrosshairPipe.Draw2dCrosshairPipeSettings draw2dCrosshairPipeSettings;
|
||||||
private OutputMatPipe outputMatPipe;
|
private OutputMatPipe outputMatPipe;
|
||||||
|
|
||||||
private String pipelineTimeString = "";
|
private String pipelineTimeString = "";
|
||||||
@@ -69,13 +71,14 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
|||||||
draw2dContoursSettings = new Draw2dContoursPipe.Draw2dContoursSettings();
|
draw2dContoursSettings = new Draw2dContoursPipe.Draw2dContoursSettings();
|
||||||
// TODO: make settable from UI? config?
|
// TODO: make settable from UI? config?
|
||||||
draw2dContoursSettings.showCentroid = false;
|
draw2dContoursSettings.showCentroid = false;
|
||||||
draw2dContoursSettings.showCrosshair = true;
|
|
||||||
draw2dContoursSettings.boxOutlineSize = 2;
|
draw2dContoursSettings.boxOutlineSize = 2;
|
||||||
draw2dContoursSettings.showRotatedBox = true;
|
draw2dContoursSettings.showRotatedBox = true;
|
||||||
draw2dContoursSettings.showMaximumBox = true;
|
draw2dContoursSettings.showMaximumBox = true;
|
||||||
draw2dContoursSettings.showMultiple = settings.multiple;
|
draw2dContoursSettings.showMultiple = settings.multiple;
|
||||||
|
|
||||||
draw2dContoursPipe = new Draw2dContoursPipe(draw2dContoursSettings, camProps);
|
draw2dContoursPipe = new Draw2dContoursPipe(draw2dContoursSettings, camProps);
|
||||||
|
draw2dCrosshairPipeSettings = new Draw2dCrosshairPipe.Draw2dCrosshairPipeSettings();
|
||||||
|
draw2dCrosshairPipeSettings.showCrosshair=true;
|
||||||
|
draw2dCrosshairPipe=new Draw2dCrosshairPipe(draw2dCrosshairPipeSettings);
|
||||||
outputMatPipe = new OutputMatPipe(settings.isBinary);
|
outputMatPipe = new OutputMatPipe(settings.isBinary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +163,10 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
|||||||
Pair<Mat, Long> draw2dContoursResult = draw2dContoursPipe.run(Pair.of(outputMatResult.getLeft(), sortContoursResult.getLeft()));
|
Pair<Mat, Long> draw2dContoursResult = draw2dContoursPipe.run(Pair.of(outputMatResult.getLeft(), sortContoursResult.getLeft()));
|
||||||
totalPipelineTimeNanos += draw2dContoursResult.getRight();
|
totalPipelineTimeNanos += draw2dContoursResult.getRight();
|
||||||
|
|
||||||
|
// takes pair of (Mat to draw on, List<RotatedRect> of sorted contours)
|
||||||
|
Pair<Mat, Long> draw2dCrosshairResult = draw2dCrosshairPipe.run(Pair.of(draw2dContoursResult.getLeft(),collect2dTargetsResult.getLeft()));
|
||||||
|
totalPipelineTimeNanos += draw2dCrosshairResult.getRight();
|
||||||
|
|
||||||
if (Main.testMode) {
|
if (Main.testMode) {
|
||||||
pipelineTimeString += String.format("PipeInit: %.2fms, ", pipeInitTimeNanos / 1000000.0);
|
pipelineTimeString += String.format("PipeInit: %.2fms, ", pipeInitTimeNanos / 1000000.0);
|
||||||
pipelineTimeString += String.format("RotateFlip: %.2fms, ", rotateFlipResult.getRight() / 1000000.0);
|
pipelineTimeString += String.format("RotateFlip: %.2fms, ", rotateFlipResult.getRight() / 1000000.0);
|
||||||
@@ -174,6 +181,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
|||||||
pipelineTimeString += String.format("Collect2dTargets: %.2fms, ", collect2dTargetsResult.getRight() / 1000000.0);
|
pipelineTimeString += String.format("Collect2dTargets: %.2fms, ", collect2dTargetsResult.getRight() / 1000000.0);
|
||||||
pipelineTimeString += String.format("OutputMat: %.2fms, ", outputMatResult.getRight() / 1000000.0);
|
pipelineTimeString += String.format("OutputMat: %.2fms, ", outputMatResult.getRight() / 1000000.0);
|
||||||
pipelineTimeString += String.format("Draw2dContours: %.2fms, ", draw2dContoursResult.getRight() / 1000000.0);
|
pipelineTimeString += String.format("Draw2dContours: %.2fms, ", draw2dContoursResult.getRight() / 1000000.0);
|
||||||
|
pipelineTimeString += String.format("Draw2dCrosshair: %.2fms, ", draw2dCrosshairResult.getRight() / 1000000.0);
|
||||||
|
|
||||||
System.out.println(pipelineTimeString);
|
System.out.println(pipelineTimeString);
|
||||||
double totalPipelineTimeMillis = totalPipelineTimeNanos / 1000000.0;
|
double totalPipelineTimeMillis = totalPipelineTimeNanos / 1000000.0;
|
||||||
@@ -186,7 +194,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
|||||||
|
|
||||||
memManager.run();
|
memManager.run();
|
||||||
|
|
||||||
return new CVPipeline2dResult(collect2dTargetsResult.getLeft(), draw2dContoursResult.getLeft(), totalPipelineTimeNanos);
|
return new CVPipeline2dResult(collect2dTargetsResult.getLeft(), draw2dCrosshairResult.getLeft(), totalPipelineTimeNanos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CVPipeline2dResult extends CVPipelineResult<Target2d> {
|
public static class CVPipeline2dResult extends CVPipelineResult<Target2d> {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
|||||||
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();
|
||||||
|
|
||||||
if (settings.showCrosshair || settings.showCentroid || settings.showMaximumBox || settings.showRotatedBox) {
|
if (settings.showCentroid || settings.showMaximumBox || settings.showRotatedBox) {
|
||||||
// input.getLeft().copyTo(processBuffer);
|
// input.getLeft().copyTo(processBuffer);
|
||||||
// processBuffer = input.getLeft();
|
// processBuffer = input.getLeft();
|
||||||
|
|
||||||
@@ -77,34 +77,32 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.showCrosshair) {
|
//Moved to Draw2dCrosshair
|
||||||
xMax.set(new double[] {camProps.centerX + 10, camProps.centerY});
|
// if (settings.showCrosshair) {
|
||||||
xMin.set(new double[] {camProps.centerX - 10, camProps.centerY});
|
// xMax.set(new double[] {camProps.centerX + 10, camProps.centerY});
|
||||||
yMax.set(new double[] {camProps.centerX, camProps.centerY + 10});
|
// xMin.set(new double[] {camProps.centerX - 10, camProps.centerY});
|
||||||
yMin.set(new double[] {camProps.centerX, camProps.centerY - 10});
|
// yMax.set(new double[] {camProps.centerX, camProps.centerY + 10});
|
||||||
Imgproc.line(input.getLeft(), xMax, xMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
// yMin.set(new double[] {camProps.centerX, camProps.centerY - 10});
|
||||||
Imgproc.line(input.getLeft(), yMax, yMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
// Imgproc.line(input.getLeft(), xMax, xMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||||
}
|
// Imgproc.line(input.getLeft(), yMax, yMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||||
|
// }
|
||||||
|
|
||||||
// processBuffer.copyTo(outputMat);
|
// processBuffer.copyTo(outputMat);
|
||||||
// processBuffer.release();
|
// processBuffer.release();
|
||||||
} else {
|
} else {
|
||||||
// input.getLeft().copyTo(outputMat);
|
// input.getLeft().copyTo(outputMat);
|
||||||
}
|
}
|
||||||
|
|
||||||
long processTime = System.nanoTime() - processStartNanos;
|
long processTime = System.nanoTime() - processStartNanos;
|
||||||
return Pair.of(input.getLeft(), processTime);
|
return Pair.of(input.getLeft(), processTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Draw2dContoursSettings {
|
public static class Draw2dContoursSettings {
|
||||||
public boolean showCentroid = false;
|
public boolean showCentroid = false;
|
||||||
public boolean showCrosshair = false;
|
|
||||||
public boolean showMultiple = false;
|
public boolean showMultiple = false;
|
||||||
public int boxOutlineSize = 0;
|
public int boxOutlineSize = 0;
|
||||||
public boolean showRotatedBox = false;
|
public boolean showRotatedBox = false;
|
||||||
public boolean showMaximumBox = false;
|
public boolean showMaximumBox = false;
|
||||||
public Color centroidColor = Color.GREEN;
|
public Color centroidColor = Color.GREEN;
|
||||||
public Color crosshairColor = Color.GREEN;
|
|
||||||
public Color rotatedBoxColor = Color.BLUE;
|
public Color rotatedBoxColor = Color.BLUE;
|
||||||
public Color maximumBoxColor = Color.RED;
|
public Color maximumBoxColor = Color.RED;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.chameleonvision.vision.pipeline.pipes;
|
||||||
|
|
||||||
|
import com.chameleonvision.util.Helpers;
|
||||||
|
import com.chameleonvision.vision.camera.CaptureStaticProperties;
|
||||||
|
import com.chameleonvision.vision.pipeline.CVPipeline2d;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.opencv.core.Mat;
|
||||||
|
import org.opencv.core.Point;
|
||||||
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Draw2dCrosshairPipe implements Pipe<Pair<Mat, List<CVPipeline2d.Target2d>>, Mat>{
|
||||||
|
|
||||||
|
private final Draw2dCrosshairPipe.Draw2dCrosshairPipeSettings settings;
|
||||||
|
private Point xMax = new Point(), xMin = new Point(), yMax = new Point(), yMin = new Point();
|
||||||
|
|
||||||
|
public Draw2dCrosshairPipe(Draw2dCrosshairPipe.Draw2dCrosshairPipeSettings settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfig(boolean showCrosshair) {
|
||||||
|
this.settings.showCrosshair = showCrosshair;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pair<Mat, Long> run(Pair<Mat,List<CVPipeline2d.Target2d>> inputPair) {
|
||||||
|
long processStartNanos = System.nanoTime();
|
||||||
|
|
||||||
|
List<CVPipeline2d.Target2d> targets = inputPair.getRight();
|
||||||
|
double x,y;
|
||||||
|
if(targets != null && !targets.isEmpty()) {
|
||||||
|
x = targets.get(0).calibratedX;
|
||||||
|
y = targets.get(0).calibratedY;
|
||||||
|
if (this.settings.showCrosshair) {
|
||||||
|
xMax.set(new double[] {x + 10, y});
|
||||||
|
xMin.set(new double[] {x - 10, y});
|
||||||
|
yMax.set(new double[] {x, y + 10});
|
||||||
|
yMin.set(new double[] {x, y - 10});
|
||||||
|
Imgproc.line(inputPair.getLeft(), xMax, xMin, Helpers.colorToScalar(this.settings.crosshairColor), 2);
|
||||||
|
Imgproc.line(inputPair.getLeft(), yMax, yMin, Helpers.colorToScalar(this.settings.crosshairColor), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// image.release();
|
||||||
|
long processTime = System.nanoTime() - processStartNanos;
|
||||||
|
return Pair.of(inputPair.getLeft(), processTime);
|
||||||
|
}
|
||||||
|
public static class Draw2dCrosshairPipeSettings{
|
||||||
|
public boolean showCrosshair =true;
|
||||||
|
public Color crosshairColor = Color.GREEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user