mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Disable drawing during color picking (#96)
Replaces showThreshold with shouldDraw
This commit is contained in:
@@ -35,18 +35,20 @@ public class Draw2dCrosshairPipe
|
||||
|
||||
@Override
|
||||
protected Void process(Pair<Mat, List<TrackedTarget>> in) {
|
||||
if (!params.shouldDraw) return null;
|
||||
|
||||
Mat image = in.getLeft();
|
||||
|
||||
if (params.m_showCrosshair) {
|
||||
if (params.showCrosshair) {
|
||||
double x = image.cols() / 2.0;
|
||||
double y = image.rows() / 2.0;
|
||||
double scale = image.cols() / 32.0;
|
||||
|
||||
switch (params.m_calibrationMode) {
|
||||
switch (params.calibrationMode) {
|
||||
case Single:
|
||||
if (!params.m_calibrationPoint.isEmpty()) {
|
||||
x = params.m_calibrationPoint.getFirst();
|
||||
y = params.m_calibrationPoint.getSecond();
|
||||
if (!params.calibrationPoint.isEmpty()) {
|
||||
x = params.calibrationPoint.getFirst();
|
||||
y = params.calibrationPoint.getSecond();
|
||||
}
|
||||
break;
|
||||
case Dual:
|
||||
@@ -59,22 +61,25 @@ public class Draw2dCrosshairPipe
|
||||
Point yMax = new Point(x, y + scale);
|
||||
Point yMin = new Point(x, y - scale);
|
||||
|
||||
Imgproc.line(image, xMax, xMin, ColorHelper.colorToScalar(params.m_crosshairColor));
|
||||
Imgproc.line(image, yMax, yMin, ColorHelper.colorToScalar(params.m_crosshairColor));
|
||||
Imgproc.line(image, xMax, xMin, ColorHelper.colorToScalar(params.crosshairColor));
|
||||
Imgproc.line(image, yMax, yMin, ColorHelper.colorToScalar(params.crosshairColor));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Draw2dCrosshairParams {
|
||||
private final RobotOffsetPointMode m_calibrationMode;
|
||||
private final DoubleCouple m_calibrationPoint;
|
||||
private final boolean m_showCrosshair = true;
|
||||
private final Color m_crosshairColor = Color.GREEN;
|
||||
public boolean showCrosshair = true;
|
||||
public Color crosshairColor = Color.GREEN;
|
||||
|
||||
public final boolean shouldDraw;
|
||||
public final RobotOffsetPointMode calibrationMode;
|
||||
public final DoubleCouple calibrationPoint;
|
||||
|
||||
public Draw2dCrosshairParams(
|
||||
RobotOffsetPointMode calibrationMode, DoubleCouple calibrationPoint) {
|
||||
m_calibrationMode = calibrationMode;
|
||||
m_calibrationPoint = calibrationPoint;
|
||||
boolean shouldDraw, RobotOffsetPointMode calibrationMode, DoubleCouple calibrationPoint) {
|
||||
this.shouldDraw = shouldDraw;
|
||||
this.calibrationMode = calibrationMode;
|
||||
this.calibrationPoint = calibrationPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,14 @@ import org.photonvision.vision.target.TrackedTarget;
|
||||
|
||||
public class Draw2dTargetsPipe
|
||||
extends MutatingPipe<
|
||||
Triple<Mat, List<TrackedTarget>, Integer>, Draw2dTargetsPipe.Draw2dContoursParams> {
|
||||
Triple<Mat, List<TrackedTarget>, Integer>, Draw2dTargetsPipe.Draw2dTargetsParams> {
|
||||
|
||||
private List<MatOfPoint> m_drawnContours = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected Void process(Triple<Mat, List<TrackedTarget>, Integer> in) {
|
||||
if (!params.shouldDraw) return null;
|
||||
|
||||
if (!in.getMiddle().isEmpty()
|
||||
&& (params.showCentroid
|
||||
|| params.showMaximumBox
|
||||
@@ -50,11 +52,11 @@ public class Draw2dTargetsPipe
|
||||
var rotatedBoxColour = ColorHelper.colorToScalar(params.rotatedBoxColor);
|
||||
var shapeColour = ColorHelper.colorToScalar(params.shapeOutlineColour);
|
||||
|
||||
for (int i = 0; i < (params.showMultiple ? in.getMiddle().size() : 1); i++) {
|
||||
for (int i = 0; i < (params.showMultipleTargets ? in.getMiddle().size() : 1); i++) {
|
||||
Point[] vertices = new Point[4];
|
||||
MatOfPoint contour = new MatOfPoint();
|
||||
|
||||
if (i != 0 && !params.showMultiple) {
|
||||
if (i != 0 && !params.showMultipleTargets) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -160,29 +162,30 @@ public class Draw2dTargetsPipe
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Draw2dContoursParams {
|
||||
public final double kPixelsToText = 0.0025;
|
||||
public final double kPixelsToThickness = 0.008;
|
||||
public final double kPixelsToOffset = 0.02;
|
||||
|
||||
public final double kPixelsToBoxThickness = 0.007;
|
||||
public final double kPixelsToCentroidRadius = 0.03;
|
||||
|
||||
public static class Draw2dTargetsParams {
|
||||
public double kPixelsToText = 0.0025;
|
||||
public double kPixelsToThickness = 0.008;
|
||||
public double kPixelsToOffset = 0.02;
|
||||
public double kPixelsToBoxThickness = 0.007;
|
||||
public double kPixelsToCentroidRadius = 0.03;
|
||||
public boolean showCentroid = true;
|
||||
public boolean showMultiple;
|
||||
public boolean showRotatedBox = true;
|
||||
public boolean showShape = false;
|
||||
public boolean showMaximumBox = true;
|
||||
public boolean showContourNumber = true;
|
||||
public Color centroidColor = Color.green; // Color.decode("#ff5ebf");
|
||||
public Color centroidColor = Color.GREEN; // Color.decode("#ff5ebf");
|
||||
public Color rotatedBoxColor = Color.BLUE;
|
||||
public Color maximumBoxColor = Color.RED;
|
||||
public Color shapeOutlineColour = Color.MAGENTA;
|
||||
public Color textColor = Color.GREEN;
|
||||
|
||||
public final boolean showMultipleTargets;
|
||||
public final boolean shouldDraw;
|
||||
|
||||
// TODO: set other params from UI/settings file?
|
||||
public Draw2dContoursParams(boolean showMultipleTargets) {
|
||||
this.showMultiple = showMultipleTargets;
|
||||
public Draw2dTargetsParams(boolean shouldDraw, boolean showMultipleTargets) {
|
||||
this.shouldDraw = shouldDraw;
|
||||
this.showMultipleTargets = showMultipleTargets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ public class Draw3dTargetsPipe
|
||||
|
||||
@Override
|
||||
protected Void process(Pair<Mat, List<TrackedTarget>> in) {
|
||||
if (!params.shouldDraw) return null;
|
||||
|
||||
for (var target : in.getRight()) {
|
||||
|
||||
// draw convex hull
|
||||
@@ -125,13 +127,18 @@ public class Draw3dTargetsPipe
|
||||
}
|
||||
|
||||
public static class Draw3dContoursParams {
|
||||
private final int radius = 2;
|
||||
private final Color color = Color.RED;
|
||||
private final TargetModel targetModel;
|
||||
private final CameraCalibrationCoefficients cameraCalibrationCoefficients;
|
||||
public int radius = 2;
|
||||
public Color color = Color.RED;
|
||||
|
||||
public final boolean shouldDraw;
|
||||
public final TargetModel targetModel;
|
||||
public final CameraCalibrationCoefficients cameraCalibrationCoefficients;
|
||||
|
||||
public Draw3dContoursParams(
|
||||
CameraCalibrationCoefficients cameraCalibrationCoefficients, TargetModel targetModel) {
|
||||
boolean shouldDraw,
|
||||
CameraCalibrationCoefficients cameraCalibrationCoefficients,
|
||||
TargetModel targetModel) {
|
||||
this.shouldDraw = shouldDraw;
|
||||
this.cameraCalibrationCoefficients = cameraCalibrationCoefficients;
|
||||
this.targetModel = targetModel;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class AdvancedPipelineSettings extends CVPipelineSettings {
|
||||
public IntegerCouple hsvSaturation = new IntegerCouple(50, 255);
|
||||
public IntegerCouple hsvValue = new IntegerCouple(50, 255);
|
||||
|
||||
public boolean outputShowThresholded = true;
|
||||
public boolean outputShouldDraw = true;
|
||||
public boolean outputShowMultipleTargets = false;
|
||||
|
||||
public boolean erode = false;
|
||||
@@ -74,7 +74,7 @@ public class AdvancedPipelineSettings extends CVPipelineSettings {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
AdvancedPipelineSettings that = (AdvancedPipelineSettings) o;
|
||||
return outputShowThresholded == that.outputShowThresholded
|
||||
return outputShouldDraw == that.outputShouldDraw
|
||||
&& outputShowMultipleTargets == that.outputShowMultipleTargets
|
||||
&& erode == that.erode
|
||||
&& dilate == that.dilate
|
||||
@@ -101,7 +101,7 @@ public class AdvancedPipelineSettings extends CVPipelineSettings {
|
||||
hsvHue,
|
||||
hsvSaturation,
|
||||
hsvValue,
|
||||
outputShowThresholded,
|
||||
outputShouldDraw,
|
||||
outputShowMultipleTargets,
|
||||
erode,
|
||||
dilate,
|
||||
|
||||
@@ -155,21 +155,24 @@ public class ColoredShapePipeline
|
||||
settings.cameraCalibration, settings.cameraPitch, settings.targetModel);
|
||||
solvePNPPipe.setParams(solvePNPParams);
|
||||
|
||||
Draw2dTargetsPipe.Draw2dContoursParams draw2dContoursParams =
|
||||
new Draw2dTargetsPipe.Draw2dContoursParams(settings.outputShowMultipleTargets);
|
||||
draw2dContoursParams.showShape = true;
|
||||
draw2dContoursParams.showMaximumBox = false;
|
||||
draw2dContoursParams.showRotatedBox = false;
|
||||
draw2DTargetsPipe.setParams(draw2dContoursParams);
|
||||
Draw2dTargetsPipe.Draw2dTargetsParams draw2DTargetsParams =
|
||||
new Draw2dTargetsPipe.Draw2dTargetsParams(
|
||||
settings.outputShouldDraw, settings.outputShowMultipleTargets);
|
||||
draw2DTargetsParams.showShape = true;
|
||||
draw2DTargetsParams.showMaximumBox = false;
|
||||
draw2DTargetsParams.showRotatedBox = false;
|
||||
draw2DTargetsPipe.setParams(draw2DTargetsParams);
|
||||
|
||||
Draw2dCrosshairPipe.Draw2dCrosshairParams draw2dCrosshairParams =
|
||||
new Draw2dCrosshairPipe.Draw2dCrosshairParams(
|
||||
settings.offsetRobotOffsetMode, settings.offsetCalibrationPoint);
|
||||
settings.outputShouldDraw,
|
||||
settings.offsetRobotOffsetMode,
|
||||
settings.offsetCalibrationPoint);
|
||||
draw2dCrosshairPipe.setParams(draw2dCrosshairParams);
|
||||
|
||||
var draw3dContoursParams =
|
||||
new Draw3dTargetsPipe.Draw3dContoursParams(
|
||||
settings.cameraCalibration, settings.targetModel);
|
||||
settings.outputShouldDraw, settings.cameraCalibration, settings.targetModel);
|
||||
draw3dTargetsPipe.setParams(draw3dContoursParams);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class DriverModePipeline
|
||||
|
||||
Draw2dCrosshairPipe.Draw2dCrosshairParams draw2dCrosshairParams =
|
||||
new Draw2dCrosshairPipe.Draw2dCrosshairParams(
|
||||
settings.offsetPointMode, settings.offsetPoint);
|
||||
true, settings.offsetPointMode, settings.offsetPoint);
|
||||
draw2dCrosshairPipe.setParams(draw2dCrosshairParams);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,18 +129,23 @@ public class ReflectivePipeline extends CVPipeline<CVPipelineResult, ReflectiveP
|
||||
settings.cornerDetectionAccuracyPercentage);
|
||||
cornerDetectionPipe.setParams(params);
|
||||
|
||||
Draw2dTargetsPipe.Draw2dContoursParams draw2dContoursParams =
|
||||
new Draw2dTargetsPipe.Draw2dContoursParams(settings.outputShowMultipleTargets);
|
||||
draw2dTargetsPipe.setParams(draw2dContoursParams);
|
||||
Draw2dTargetsPipe.Draw2dTargetsParams draw2DTargetsParams =
|
||||
new Draw2dTargetsPipe.Draw2dTargetsParams(
|
||||
settings.outputShouldDraw, settings.outputShowMultipleTargets);
|
||||
draw2dTargetsPipe.setParams(draw2DTargetsParams);
|
||||
|
||||
Draw2dCrosshairPipe.Draw2dCrosshairParams draw2dCrosshairParams =
|
||||
new Draw2dCrosshairPipe.Draw2dCrosshairParams(
|
||||
settings.offsetRobotOffsetMode, settings.offsetCalibrationPoint);
|
||||
settings.outputShouldDraw,
|
||||
settings.offsetRobotOffsetMode,
|
||||
settings.offsetCalibrationPoint);
|
||||
draw2dCrosshairPipe.setParams(draw2dCrosshairParams);
|
||||
|
||||
var draw3dContoursParams =
|
||||
new Draw3dTargetsPipe.Draw3dContoursParams(
|
||||
frameStaticProperties.cameraCalibration, settings.targetModel);
|
||||
settings.outputShouldDraw,
|
||||
frameStaticProperties.cameraCalibration,
|
||||
settings.targetModel);
|
||||
draw3dTargetsPipe.setParams(draw3dContoursParams);
|
||||
|
||||
var solvePNPParams =
|
||||
|
||||
Reference in New Issue
Block a user