mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-28 02:11:40 +00:00
2022 grouping and test mode updates (#381)
Add 2022 images, "2orMore" grouping mode, and 2022 test mode Test mode now preserves old settings
This commit is contained in:
@@ -18,6 +18,7 @@ package org.photonvision.common.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import edu.wpi.first.cscore.CameraServerCvJNI;
|
||||
import edu.wpi.first.math.util.Units;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -97,6 +98,26 @@ public class TestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public enum WPI2022Image {
|
||||
kTerminal12ft6in(Units.feetToMeters(12.5)),
|
||||
kTerminal22ft6in(Units.feetToMeters(22.5));
|
||||
|
||||
public static double FOV = 68.5;
|
||||
|
||||
public final double distanceMeters;
|
||||
public final Path path;
|
||||
|
||||
Path getPath() {
|
||||
var filename = this.toString().substring(1).replace('_', '-');
|
||||
return Path.of("2022", "WPI", filename + ".png");
|
||||
}
|
||||
|
||||
WPI2022Image(double distanceMeters) {
|
||||
this.distanceMeters = distanceMeters;
|
||||
this.path = getPath();
|
||||
}
|
||||
}
|
||||
|
||||
public enum PolygonTestImages {
|
||||
kPolygons;
|
||||
|
||||
@@ -133,7 +154,8 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
private static Path getResourcesFolderPath(boolean testMode) {
|
||||
return Path.of("../test-resources").toAbsolutePath();
|
||||
System.out.println("CWD: " + Path.of("").toAbsolutePath().toString());
|
||||
return Path.of(testMode ? "" : "../" + "test-resources").toAbsolutePath();
|
||||
}
|
||||
|
||||
public static Path getTestMode2019ImagePath() {
|
||||
@@ -148,6 +170,12 @@ public class TestUtils {
|
||||
.resolve(WPI2020Image.kBlueGoal_108in_Center.path);
|
||||
}
|
||||
|
||||
public static Path getTestMode2022ImagePath() {
|
||||
return getResourcesFolderPath(true)
|
||||
.resolve("testimages")
|
||||
.resolve(WPI2022Image.kTerminal22ft6in.path);
|
||||
}
|
||||
|
||||
public static Path getTestImagesPath(boolean testMode) {
|
||||
return getResourcesFolderPath(testMode).resolve("testimages");
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.photonvision.vision.opencv.CVMat;
|
||||
* path}.
|
||||
*/
|
||||
public class FileFrameProvider implements FrameProvider {
|
||||
public static final int MAX_FPS = 120;
|
||||
public static final int MAX_FPS = 10;
|
||||
private static int count = 0;
|
||||
|
||||
private final int thisIndex = count++;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package org.photonvision.vision.opencv;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.opencv.core.CvType;
|
||||
@@ -192,7 +194,11 @@ public class Contour implements Releasable {
|
||||
|| secondContour.isIntersecting(firstContour, intersectionDirection);
|
||||
}
|
||||
|
||||
private static Contour combineContours(Contour... contours) {
|
||||
public static Contour combineContours(Contour... contours) {
|
||||
return combineContourList(Arrays.asList(contours));
|
||||
}
|
||||
|
||||
public static Contour combineContourList(Collection<Contour> contours) {
|
||||
var points = new MatOfPoint();
|
||||
|
||||
for (var contour : contours) {
|
||||
|
||||
@@ -18,7 +18,8 @@ package org.photonvision.vision.opencv;
|
||||
|
||||
public enum ContourGroupingMode {
|
||||
Single(1),
|
||||
Dual(2);
|
||||
Dual(2),
|
||||
TwoOrMore(2);
|
||||
|
||||
public final int count;
|
||||
|
||||
|
||||
@@ -41,6 +41,16 @@ public class GroupContoursPipe
|
||||
for (var contour : input) {
|
||||
m_targets.add(new PotentialTarget(contour));
|
||||
}
|
||||
}
|
||||
// Check if we have at least 2 targets for 2 or more
|
||||
// This will only ever return 1 contour!
|
||||
else if (params.getGroup() == ContourGroupingMode.TwoOrMore
|
||||
&& input.size() >= ContourGroupingMode.TwoOrMore.count) {
|
||||
// Just blob everything together
|
||||
Contour groupedContour = Contour.combineContourList(input);
|
||||
if (groupedContour != null) {
|
||||
m_targets.add(new PotentialTarget(groupedContour, input));
|
||||
}
|
||||
} else {
|
||||
int groupingCount = params.getGroup().count;
|
||||
|
||||
@@ -52,14 +62,12 @@ public class GroupContoursPipe
|
||||
|
||||
for (int i = 0; i < input.size() - 1; i++) {
|
||||
// make a list of the desired count of contours to group
|
||||
List<Contour> groupingSet;
|
||||
// (Just make sure we don't get an index out of bounds exception
|
||||
if (i < 0 || i + groupingCount > input.size()) continue;
|
||||
|
||||
// If we're in two or more mode, just try to group everything
|
||||
List<Contour> groupingSet = input.subList(i, i + groupingCount);
|
||||
|
||||
// TODO: are these try/catch avoidable?
|
||||
try {
|
||||
groupingSet = input.subList(i, i + groupingCount);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
// FYI: This method only takes 2 contours!
|
||||
Contour groupedContour =
|
||||
|
||||
@@ -21,10 +21,7 @@ import java.util.Objects;
|
||||
import org.photonvision.common.util.numbers.DoubleCouple;
|
||||
import org.photonvision.common.util.numbers.IntegerCouple;
|
||||
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
|
||||
import org.photonvision.vision.opencv.ContourGroupingMode;
|
||||
import org.photonvision.vision.opencv.ContourIntersectionDirection;
|
||||
import org.photonvision.vision.opencv.ContourShape;
|
||||
import org.photonvision.vision.pipe.impl.CornerDetectionPipe;
|
||||
|
||||
@JsonTypeName("ColoredShapePipelineSettings")
|
||||
public class ColoredShapePipelineSettings extends AdvancedPipelineSettings {
|
||||
@@ -37,23 +34,10 @@ public class ColoredShapePipelineSettings extends AdvancedPipelineSettings {
|
||||
public int minDist = 20;
|
||||
public int maxCannyThresh = 90;
|
||||
public int circleAccuracy = 20;
|
||||
// how many contours to attempt to group (Single, Dual)
|
||||
public ContourGroupingMode contourGroupingMode = ContourGroupingMode.Single;
|
||||
|
||||
// the direction in which contours must intersect to be considered intersecting
|
||||
public ContourIntersectionDirection contourIntersection = ContourIntersectionDirection.Up;
|
||||
|
||||
// 3d settings
|
||||
public CameraCalibrationCoefficients cameraCalibration;
|
||||
|
||||
// Corner detection settings
|
||||
public CornerDetectionPipe.DetectionStrategy cornerDetectionStrategy =
|
||||
CornerDetectionPipe.DetectionStrategy.APPROX_POLY_DP_AND_EXTREME_CORNERS;
|
||||
public boolean cornerDetectionUseConvexHulls = true;
|
||||
public boolean cornerDetectionExactSideCount = false;
|
||||
public int cornerDetectionSideCount = 4;
|
||||
public double cornerDetectionAccuracyPercentage = 10;
|
||||
|
||||
public boolean erode = false;
|
||||
public boolean dilate = false;
|
||||
|
||||
|
||||
@@ -17,26 +17,9 @@
|
||||
package org.photonvision.vision.pipeline;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.photonvision.vision.opencv.ContourGroupingMode;
|
||||
import org.photonvision.vision.opencv.ContourIntersectionDirection;
|
||||
import org.photonvision.vision.pipe.impl.CornerDetectionPipe;
|
||||
|
||||
@JsonTypeName("ReflectivePipelineSettings")
|
||||
public class ReflectivePipelineSettings extends AdvancedPipelineSettings {
|
||||
// how many contours to attempt to group (Single, Dual)
|
||||
public ContourGroupingMode contourGroupingMode = ContourGroupingMode.Single;
|
||||
|
||||
// the direction in which contours must intersect to be considered intersecting
|
||||
public ContourIntersectionDirection contourIntersection = ContourIntersectionDirection.Up;
|
||||
|
||||
// Corner detection settings
|
||||
public CornerDetectionPipe.DetectionStrategy cornerDetectionStrategy =
|
||||
CornerDetectionPipe.DetectionStrategy.APPROX_POLY_DP_AND_EXTREME_CORNERS;
|
||||
public boolean cornerDetectionUseConvexHulls = true;
|
||||
public boolean cornerDetectionExactSideCount = false;
|
||||
public int cornerDetectionSideCount = 4;
|
||||
public double cornerDetectionAccuracyPercentage = 10;
|
||||
|
||||
public ReflectivePipelineSettings() {
|
||||
super();
|
||||
pipelineType = PipelineType.Reflective;
|
||||
|
||||
Reference in New Issue
Block a user