Skip to content

Commit 21d58e3

Browse files
Only show images during tests when requested via project property
1 parent 9b8c9c7 commit 21d58e3

File tree

10 files changed

+86
-30
lines changed

10 files changed

+86
-30
lines changed

photon-core/src/main/java/org/photonvision/common/util/TestUtils.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,24 @@ public static CameraCalibrationCoefficients getLaptop() {
350350
return getCoeffs("laptop.json", true);
351351
}
352352

353-
private static final int DefaultTimeoutMillis = 5000;
353+
/**
354+
* Checks if the specified test variant or one of its parent groups was requested.
355+
*
356+
* @param key The test variant key, groups separated by the '.' character
357+
*/
358+
public static boolean testVariantEnabled(String key) {
359+
String[] words = key.split("\\.");
360+
String subkey = "junit";
361+
// Check groups from most general to most specific
362+
for (int i = 0; i < words.length; i++) {
363+
subkey += "." + words[i];
364+
// Only check for key presence, allowing for any value (including no value)
365+
if (!"UNDEFINED".equals(System.getProperty(subkey, "UNDEFINED"))) return true;
366+
}
367+
return false;
368+
}
369+
370+
private static final int DefaultTimeoutMillis = 0; // Indefinite timeout
354371

355372
public static void showImage(Mat frame, String title, int timeoutMs) {
356373
if (frame.empty()) return;

photon-core/src/test/java/org/photonvision/vision/frame/provider/FileFrameProviderTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public void Load2019ImageOnceTest() {
5555
assertEquals(320, goodFrameCols);
5656
assertEquals(240, goodFrameRows);
5757

58-
TestUtils.showImage(goodFrame.colorImage.getMat(), "2019");
58+
if (TestUtils.testVariantEnabled("review.frame")) {
59+
TestUtils.showImage(goodFrame.colorImage.getMat(), "2019");
60+
}
5961

6062
var badFilePath = Paths.get("bad.jpg"); // this file does not exist
6163

@@ -88,7 +90,9 @@ public void Load2020ImageOnceTest() {
8890
assertEquals(640, goodFrameCols);
8991
assertEquals(480, goodFrameRows);
9092

91-
TestUtils.showImage(goodFrame.colorImage.getMat(), "2020");
93+
if (TestUtils.testVariantEnabled("review.frame")) {
94+
TestUtils.showImage(goodFrame.colorImage.getMat(), "2020");
95+
}
9296

9397
var badFilePath = Paths.get("bad.jpg"); // this file does not exist
9498

photon-core/src/test/java/org/photonvision/vision/pipeline/AprilTagTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public void testApriltagFacingCamera() {
6666
outputPipe.process(
6767
pipelineResult.inputAndOutputFrame, pipeline.getSettings(), pipelineResult.targets);
6868

69-
TestUtils.showImage(ret.inputAndOutputFrame.processedImage.getMat(), "Pipeline output", 999999);
69+
if (TestUtils.testVariantEnabled("review.pipeline.apriltag")) {
70+
TestUtils.showImage(ret.inputAndOutputFrame.processedImage.getMat(), "Pipeline output");
71+
}
7072

7173
// these numbers are not *accurate*, but they are known and expected
7274
var target = pipelineResult.targets.get(0);
@@ -128,7 +130,9 @@ public void testApriltagDistorted() {
128130
outputPipe.process(
129131
pipelineResult.inputAndOutputFrame, pipeline.getSettings(), pipelineResult.targets);
130132

131-
TestUtils.showImage(ret.inputAndOutputFrame.processedImage.getMat(), "Pipeline output", 999999);
133+
if (TestUtils.testVariantEnabled("review.pipeline.apriltag")) {
134+
TestUtils.showImage(ret.inputAndOutputFrame.processedImage.getMat(), "Pipeline output");
135+
}
132136

133137
// these numbers are not *accurate*, but they are known and expected
134138
var pose = pipelineResult.targets.get(0).getBestCameraToTarget3d();

photon-core/src/test/java/org/photonvision/vision/pipeline/ArucoPipelineTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public void testApriltagFacingCamera() {
6666
outputPipe.process(
6767
pipelineResult.inputAndOutputFrame, pipeline.getSettings(), pipelineResult.targets);
6868

69-
TestUtils.showImage(ret.inputAndOutputFrame.processedImage.getMat(), "Pipeline output", 999999);
69+
if (TestUtils.testVariantEnabled("review.pipeline.aruco")) {
70+
TestUtils.showImage(ret.inputAndOutputFrame.processedImage.getMat(), "Pipeline output");
71+
}
7072

7173
// these numbers are not *accurate*, but they are known and expected
7274
var target = pipelineResult.targets.get(0);

photon-core/src/test/java/org/photonvision/vision/pipeline/Calibrate3dPipeTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static void calibrateCommon(
242242

243243
// TestUtils.showImage(output.inputAndOutputFrame.processedImage.getMat(),
244244
// file.getName(),
245-
// 1);
245+
// TestUtils.testVariantEnabled("review.pipeline.calibrate3d"));
246246
output.release();
247247
frame.release();
248248
}
@@ -308,7 +308,9 @@ private void visuallyDebugDistortion(
308308
undistorted,
309309
cal.cameraIntrinsics.getAsMatOfDouble(),
310310
cal.distCoeffs.getAsMatOfDouble());
311-
TestUtils.showImage(undistorted, "undistorted " + file.getName(), 1);
311+
if (TestUtils.testVariantEnabled("review.pipeline.calibrate3d")) {
312+
TestUtils.showImage(undistorted, "undistorted " + file.getName());
313+
}
312314
raw.release();
313315
undistorted.release();
314316
}

photon-core/src/test/java/org/photonvision/vision/pipeline/CirclePNPTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public void testCircle() {
111111
CVPipelineResult pipelineResult = pipeline.run(frameProvider.get(), QuirkyCamera.DefaultCamera);
112112
TestUtils.printTestResultsWithLocation(pipelineResult);
113113

114-
TestUtils.showImage(
115-
pipelineResult.inputAndOutputFrame.colorImage.getMat(), "Pipeline output", 999999);
114+
if (TestUtils.testVariantEnabled("review.pipeline.circlepnp")) {
115+
TestUtils.showImage(
116+
pipelineResult.inputAndOutputFrame.colorImage.getMat(), "Pipeline output");
117+
}
116118
}
117119

118120
private static void continuouslyRunPipeline(Frame frame, ReflectivePipelineSettings settings) {

photon-core/src/test/java/org/photonvision/vision/pipeline/ColoredShapePipelineTest.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ public static void testTriangleDetection(
3232
ColoredShapePipeline pipeline, ColoredShapePipelineSettings settings, Frame frame) {
3333
pipeline.settings = settings;
3434
CVPipelineResult colouredShapePipelineResult = pipeline.run(frame, QuirkyCamera.DefaultCamera);
35-
TestUtils.showImage(
36-
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
37-
"Pipeline output: Triangle.");
35+
if (TestUtils.testVariantEnabled("review.pipeline.shape")) {
36+
TestUtils.showImage(
37+
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
38+
"Pipeline output: Triangle.");
39+
}
3840
TestUtils.printTestResults(colouredShapePipelineResult);
3941
}
4042

@@ -43,9 +45,11 @@ public static void testQuadrilateralDetection(
4345
settings.contourShape = ContourShape.Quadrilateral;
4446
pipeline.settings = settings;
4547
CVPipelineResult colouredShapePipelineResult = pipeline.run(frame, QuirkyCamera.DefaultCamera);
46-
TestUtils.showImage(
47-
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
48-
"Pipeline output: Quadrilateral.");
48+
if (TestUtils.testVariantEnabled("review.pipeline.shape")) {
49+
TestUtils.showImage(
50+
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
51+
"Pipeline output: Quadrilateral.");
52+
}
4953
TestUtils.printTestResults(colouredShapePipelineResult);
5054
}
5155

@@ -54,9 +58,11 @@ public static void testCustomShapeDetection(
5458
settings.contourShape = ContourShape.Custom;
5559
pipeline.settings = settings;
5660
CVPipelineResult colouredShapePipelineResult = pipeline.run(frame, QuirkyCamera.DefaultCamera);
57-
TestUtils.showImage(
58-
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
59-
"Pipeline output: Custom.");
61+
if (TestUtils.testVariantEnabled("review.pipeline.shape")) {
62+
TestUtils.showImage(
63+
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
64+
"Pipeline output: Custom.");
65+
}
6066
TestUtils.printTestResults(colouredShapePipelineResult);
6167
}
6268

@@ -66,9 +72,11 @@ public static void testCircleShapeDetection(
6672
settings.contourShape = ContourShape.Circle;
6773
pipeline.settings = settings;
6874
CVPipelineResult colouredShapePipelineResult = pipeline.run(frame, QuirkyCamera.DefaultCamera);
69-
TestUtils.showImage(
70-
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
71-
"Pipeline output: Circle.");
75+
if (TestUtils.testVariantEnabled("review.pipeline.shape")) {
76+
TestUtils.showImage(
77+
colouredShapePipelineResult.inputAndOutputFrame.processedImage.getMat(),
78+
"Pipeline output: Circle.");
79+
}
7280
TestUtils.printTestResults(colouredShapePipelineResult);
7381
}
7482

photon-core/src/test/java/org/photonvision/vision/pipeline/ReflectivePipelineTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public void test2019() {
5757
pipeline.getSettings().hueInverted);
5858
frameProvider.requestHsvSettings(hsvParams);
5959

60-
TestUtils.showImage(frameProvider.get().colorImage.getMat(), "Pipeline input", 1);
60+
if (TestUtils.testVariantEnabled("review.pipeline.reflective")) {
61+
TestUtils.showImage(frameProvider.get().colorImage.getMat(), "Pipeline input");
62+
}
6163

6264
CVPipelineResult pipelineResult;
6365

@@ -67,7 +69,10 @@ public void test2019() {
6769
assertTrue(pipelineResult.hasTargets());
6870
assertEquals(2, pipelineResult.targets.size(), "Target count wrong!");
6971

70-
TestUtils.showImage(pipelineResult.inputAndOutputFrame.colorImage.getMat(), "Pipeline output");
72+
if (TestUtils.testVariantEnabled("review.pipeline.reflective")) {
73+
TestUtils.showImage(
74+
pipelineResult.inputAndOutputFrame.colorImage.getMat(), "Pipeline output");
75+
}
7176
}
7277

7378
@Test
@@ -88,8 +93,10 @@ public void test2020() {
8893
CVPipelineResult pipelineResult = pipeline.run(frameProvider.get(), QuirkyCamera.DefaultCamera);
8994
TestUtils.printTestResults(pipelineResult);
9095

91-
TestUtils.showImage(
92-
pipelineResult.inputAndOutputFrame.processedImage.getMat(), "Pipeline output");
96+
if (TestUtils.testVariantEnabled("review.pipeline.reflective")) {
97+
TestUtils.showImage(
98+
pipelineResult.inputAndOutputFrame.processedImage.getMat(), "Pipeline output");
99+
}
93100
}
94101

95102
private static void continuouslyRunPipeline(Frame frame, ReflectivePipelineSettings settings) {

photon-core/src/test/java/org/photonvision/vision/pipeline/SolvePNPTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ public void test2019() {
118118
outputPipe.process(
119119
pipelineResult.inputAndOutputFrame, pipeline.getSettings(), pipelineResult.targets);
120120

121-
TestUtils.showImage(
122-
pipelineResult.inputAndOutputFrame.processedImage.getMat(), "Pipeline output", 999999);
121+
if (TestUtils.testVariantEnabled("review.pipeline.solvepnp")) {
122+
TestUtils.showImage(
123+
pipelineResult.inputAndOutputFrame.processedImage.getMat(), "Pipeline output");
124+
}
123125

124126
var pose = pipelineResult.targets.get(0).getBestCameraToTarget3d();
125127
// these numbers are not *accurate*, but they are known and expected
@@ -173,8 +175,10 @@ public void test2020() {
173175
outputPipe.process(
174176
pipelineResult.inputAndOutputFrame, pipeline.getSettings(), pipelineResult.targets);
175177

176-
TestUtils.showImage(
177-
pipelineResult.inputAndOutputFrame.processedImage.getMat(), "Pipeline output", 999999);
178+
if (TestUtils.testVariantEnabled("review.pipeline.solvepnp")) {
179+
TestUtils.showImage(
180+
pipelineResult.inputAndOutputFrame.processedImage.getMat(), "Pipeline output");
181+
}
178182

179183
var pose = pipelineResult.targets.get(0).getBestCameraToTarget3d();
180184
// these numbers are not *accurate*, but they are known and expected

shared/common.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ tasks.register('testHeadless', Test) {
7474
workingDir = new File("${rootDir}")
7575
}
7676

77+
tasks.withType(Test) {
78+
systemProperties.putAll(project.properties.findAll { key, value ->
79+
key.startsWith("junit.")
80+
})
81+
}
82+
7783
jacoco {
7884
toolVersion = "0.8.10"
7985
reportsDirectory = layout.buildDirectory.dir('customJacocoReportDir')

0 commit comments

Comments
 (0)