package org.photonvision.common; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.photonvision.common.util.TestUtils; import org.photonvision.common.util.math.MathUtils; import org.photonvision.common.util.numbers.NumberListUtils; import org.photonvision.vision.frame.FrameProvider; import org.photonvision.vision.frame.provider.FileFrameProvider; import org.photonvision.vision.opencv.CVMat; import org.photonvision.vision.opencv.ContourGroupingMode; import org.photonvision.vision.opencv.ContourIntersectionDirection; import org.photonvision.vision.pipeline.CVPipeline; import org.photonvision.vision.pipeline.CVPipelineResult; import org.photonvision.vision.pipeline.ReflectivePipeline; /** Various tests that check performance on long-running tasks (i.e. a pipeline) */ public class BenchmarkTest { @BeforeAll public static void init() { TestUtils.loadLibraries(); } @Test @Order(1) public void Reflective240pBenchmark() { var pipeline = new ReflectivePipeline(); pipeline.getSettings().hsvHue.set(60, 100); pipeline.getSettings().hsvSaturation.set(100, 255); pipeline.getSettings().hsvValue.set(190, 255); pipeline.getSettings().outputShowThresholded = true; pipeline.getSettings().outputShowMultipleTargets = true; pipeline.getSettings().contourGroupingMode = ContourGroupingMode.Dual; pipeline.getSettings().contourIntersection = ContourIntersectionDirection.Up; var frameProvider = new FileFrameProvider( TestUtils.getWPIImagePath(TestUtils.WPI2019Image.kCargoSideStraightDark72in), TestUtils.WPI2019Image.FOV); frameProvider.setImageReloading(true); benchmarkPipeline(frameProvider, pipeline, 5); } @Test @Order(1) public void Reflective480pBenchmark() { var pipeline = new ReflectivePipeline(); pipeline.getSettings().hsvHue.set(60, 100); pipeline.getSettings().hsvSaturation.set(200, 255); pipeline.getSettings().hsvValue.set(200, 255); pipeline.getSettings().outputShowThresholded = true; var frameProvider = new FileFrameProvider( TestUtils.getWPIImagePath(TestUtils.WPI2020Image.kBlueGoal_084in_Center), TestUtils.WPI2020Image.FOV); frameProvider.setImageReloading(true); benchmarkPipeline(frameProvider, pipeline, 5); } @Test @Order(3) public void Reflective720pBenchmark() { var pipeline = new ReflectivePipeline(); pipeline.getSettings().hsvHue.set(60, 100); pipeline.getSettings().hsvSaturation.set(200, 255); pipeline.getSettings().hsvValue.set(200, 255); pipeline.getSettings().outputShowThresholded = true; var frameProvider = new FileFrameProvider( TestUtils.getWPIImagePath(TestUtils.WPI2020Image.kBlueGoal_084in_Center_720p), TestUtils.WPI2020Image.FOV); frameProvider.setImageReloading(true); benchmarkPipeline(frameProvider, pipeline, 5); } @Test @Order(4) public void Reflective1920x1440Benchmark() { var pipeline = new ReflectivePipeline(); pipeline.getSettings().hsvHue.set(60, 100); pipeline.getSettings().hsvSaturation.set(100, 255); pipeline.getSettings().hsvValue.set(190, 255); pipeline.getSettings().outputShowThresholded = true; pipeline.getSettings().outputShowMultipleTargets = true; pipeline.getSettings().contourGroupingMode = ContourGroupingMode.Dual; pipeline.getSettings().contourIntersection = ContourIntersectionDirection.Up; var frameProvider = new FileFrameProvider( TestUtils.getWPIImagePath(TestUtils.WPI2019Image.kCargoStraightDark72in_HighRes), TestUtils.WPI2019Image.FOV); frameProvider.setImageReloading(true); benchmarkPipeline(frameProvider, pipeline, 5); } private static
void benchmarkPipeline(
FrameProvider frameProvider, P pipeline, int secondsToRun) {
CVMat.enablePrint(false);
// warmup for 5 loops.
System.out.println("Warming up for 5 loops...");
for (int i = 0; i < 5; i++) {
pipeline.run(frameProvider.get());
}
final List