2020-07-02 22:02:21 -04:00
|
|
|
/*
|
2020-12-31 19:57:51 -08:00
|
|
|
* Copyright (C) Photon Vision.
|
2020-07-02 22:02:21 -04:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-06-27 14:58:03 -07:00
|
|
|
package org.photonvision.common;
|
|
|
|
|
|
2020-06-12 19:58:58 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
2020-06-28 04:40:43 -04:00
|
|
|
import org.junit.jupiter.api.Order;
|
2020-06-12 19:58:58 -04:00
|
|
|
import org.junit.jupiter.api.Test;
|
2020-06-28 04:40:43 -04:00
|
|
|
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.ReflectivePipeline;
|
Bootup sprint (#18)
* Did some stuff
* Fix gradle, start implementing mjpeg frame consumer
* Did some stuff
* bade changes
* rename camera config to USBCameraConfiguration, add name
* unrename cameraconfiguration
* Add pub/sub framework
* Add setResolution to mjpeg frame consumer
* add NTDataConsumer
* Add some totally broken hsv hacks
* Start refactoring UI data
* Update index.js
* Commit and push, he says
* Fix up some errors
* Fix input tab
* Fix fps
* Update index.js
* Add pipeline field setting, update PipelineManager, fix nullpointers and USBCameraSettables
* Change v-model to point to data()
* update hsv to use mutations
* Work on saving, fix hsv
* Rename shouldErode/shouldDilate to erode and dilate
* Hook all the tabs up to the Store
* Change handleData to handlePipelineData
* camera quirk redo, add ICCSub to SocketHandler
* Fix some property names
* Fixed tons of naming in UI, fix backend for multi-val PSCs, fix PSC enums
* change pipeline type to an int in store
* Fix mutation naming
* Attempt threshold fix
* Update SocketHandler.java
* Add truthy data sending
* Start adding logging support
* [UI] Add delay to slider input boxes (#1)
* [UI] [Backend] potentially fix camera settings, various logging tweaks
* Don't release raw input mat
* add setVideoModeIndex to vision settables
* Implement pipeline index in socket handler, add framework for renaming/changing pipes
* (ish) get pipeline change working
* Create index.html
* Cleanups, fix pipeline index bug, fix stream res for MJPG, add dashboard stream (unused)
* Refactor UI to use mutatePipeline, send pipeline results
* Update NetworkConfig.java
* Change double to number
* Run spotless
* Fix reversal of large/small comparators
* Fix left/right
* Fix pitch/yaw calculation bug, fix area bug
* Use Vue.set instead of assignment
This fixes {{ }}
* Update App.vue
* run spotless
* Actually add pipelines and reassign indecies
* Delete old pipeline configs
Fixes duplication on renaming pipeline
* Start working on deleting pipes
* Fix camera nickname change
* run spotless
* Fix some test stuff
* Update VisionModuleManagerTest.java
* vision source manager test is still broken
* Fix VisionSourceManager test
* Apply spotless 2 electric boogaloo
Co-authored-by: Banks Troutman <btrout.dhrs@gmail.com>
Co-authored-by: Declan Freeman-Gleason <declanfreemangleason@gmail.com>
Co-authored-by: Aaryan Agrawal <54345060+13Ducks@users.noreply.github.com>
2020-07-07 01:01:58 -07:00
|
|
|
import org.photonvision.vision.pipeline.result.CVPipelineResult;
|
2020-06-12 19:58:58 -04:00
|
|
|
|
|
|
|
|
/** Various tests that check performance on long-running tasks (i.e. a pipeline) */
|
|
|
|
|
public class BenchmarkTest {
|
|
|
|
|
@BeforeAll
|
|
|
|
|
public static void init() {
|
|
|
|
|
TestUtils.loadLibraries();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2020-06-28 04:40:43 -04:00
|
|
|
@Order(1)
|
2020-06-12 19:58:58 -04:00
|
|
|
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);
|
2020-08-20 14:45:28 -04:00
|
|
|
pipeline.getSettings().outputShouldDraw = true;
|
2020-06-12 19:58:58 -04:00
|
|
|
pipeline.getSettings().outputShowMultipleTargets = true;
|
|
|
|
|
pipeline.getSettings().contourGroupingMode = ContourGroupingMode.Dual;
|
|
|
|
|
pipeline.getSettings().contourIntersection = ContourIntersectionDirection.Up;
|
|
|
|
|
|
|
|
|
|
var frameProvider =
|
|
|
|
|
new FileFrameProvider(
|
2020-08-08 14:21:38 -04:00
|
|
|
TestUtils.getWPIImagePath(TestUtils.WPI2019Image.kCargoSideStraightDark72in, false),
|
2020-06-12 19:58:58 -04:00
|
|
|
TestUtils.WPI2019Image.FOV);
|
|
|
|
|
|
|
|
|
|
benchmarkPipeline(frameProvider, pipeline, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2020-06-28 04:40:43 -04:00
|
|
|
@Order(1)
|
2020-06-12 19:58:58 -04:00
|
|
|
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);
|
2020-08-20 14:45:28 -04:00
|
|
|
pipeline.getSettings().outputShouldDraw = true;
|
2020-06-12 19:58:58 -04:00
|
|
|
|
|
|
|
|
var frameProvider =
|
|
|
|
|
new FileFrameProvider(
|
2020-08-08 14:21:38 -04:00
|
|
|
TestUtils.getWPIImagePath(TestUtils.WPI2020Image.kBlueGoal_084in_Center, false),
|
2020-06-12 21:09:47 -04:00
|
|
|
TestUtils.WPI2020Image.FOV);
|
|
|
|
|
|
|
|
|
|
benchmarkPipeline(frameProvider, pipeline, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2020-06-28 04:40:43 -04:00
|
|
|
@Order(3)
|
2020-06-12 21:09:47 -04:00
|
|
|
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);
|
2020-08-20 14:45:28 -04:00
|
|
|
pipeline.getSettings().outputShouldDraw = true;
|
2020-06-12 21:09:47 -04:00
|
|
|
|
|
|
|
|
var frameProvider =
|
|
|
|
|
new FileFrameProvider(
|
2020-08-08 14:21:38 -04:00
|
|
|
TestUtils.getWPIImagePath(TestUtils.WPI2020Image.kBlueGoal_084in_Center_720p, false),
|
2020-06-12 21:09:47 -04:00
|
|
|
TestUtils.WPI2020Image.FOV);
|
2020-06-12 19:58:58 -04:00
|
|
|
|
|
|
|
|
benchmarkPipeline(frameProvider, pipeline, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2020-06-28 04:40:43 -04:00
|
|
|
@Order(4)
|
2020-06-12 19:58:58 -04:00
|
|
|
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);
|
2020-08-20 14:45:28 -04:00
|
|
|
pipeline.getSettings().outputShouldDraw = true;
|
2020-06-12 19:58:58 -04:00
|
|
|
pipeline.getSettings().outputShowMultipleTargets = true;
|
|
|
|
|
pipeline.getSettings().contourGroupingMode = ContourGroupingMode.Dual;
|
|
|
|
|
pipeline.getSettings().contourIntersection = ContourIntersectionDirection.Up;
|
|
|
|
|
|
|
|
|
|
var frameProvider =
|
|
|
|
|
new FileFrameProvider(
|
2020-08-08 14:21:38 -04:00
|
|
|
TestUtils.getWPIImagePath(TestUtils.WPI2019Image.kCargoStraightDark72in_HighRes, false),
|
2020-06-12 19:58:58 -04:00
|
|
|
TestUtils.WPI2019Image.FOV);
|
|
|
|
|
|
|
|
|
|
benchmarkPipeline(frameProvider, pipeline, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static <P extends CVPipeline> void benchmarkPipeline(
|
2020-06-28 04:40:43 -04:00
|
|
|
FrameProvider frameProvider, P pipeline, int secondsToRun) {
|
2020-06-12 19:58:58 -04:00
|
|
|
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<Double> processingTimes = new ArrayList<>();
|
|
|
|
|
final List<Double> latencyTimes = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
var frameProps = frameProvider.get().frameStaticProperties;
|
|
|
|
|
|
|
|
|
|
// begin benchmark
|
2020-06-15 23:35:10 -04:00
|
|
|
System.out.println(
|
|
|
|
|
"Beginning "
|
|
|
|
|
+ secondsToRun
|
|
|
|
|
+ " second benchmark at resolution "
|
|
|
|
|
+ frameProps.imageWidth
|
|
|
|
|
+ "x"
|
|
|
|
|
+ frameProps.imageHeight);
|
2020-06-12 19:58:58 -04:00
|
|
|
var benchmarkStartMillis = System.currentTimeMillis();
|
|
|
|
|
do {
|
|
|
|
|
CVPipelineResult pipelineResult = pipeline.run(frameProvider.get());
|
|
|
|
|
pipelineResult.release();
|
2020-06-12 21:09:47 -04:00
|
|
|
processingTimes.add(pipelineResult.processingMillis);
|
|
|
|
|
latencyTimes.add(pipelineResult.getLatencyMillis());
|
2020-06-12 19:58:58 -04:00
|
|
|
} while (System.currentTimeMillis() - benchmarkStartMillis < secondsToRun * 1000);
|
|
|
|
|
System.out.println("Benchmark complete.");
|
|
|
|
|
|
|
|
|
|
var processingMin = Collections.min(processingTimes);
|
|
|
|
|
var processingMean = NumberListUtils.mean(processingTimes);
|
|
|
|
|
var processingMax = Collections.max(processingTimes);
|
|
|
|
|
|
|
|
|
|
var latencyMin = Collections.min(latencyTimes);
|
|
|
|
|
var latencyMean = NumberListUtils.mean(latencyTimes);
|
|
|
|
|
var latencyMax = Collections.max(latencyTimes);
|
|
|
|
|
|
|
|
|
|
String processingResult =
|
|
|
|
|
"Processing times - "
|
|
|
|
|
+ "Min: "
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(processingMin, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ "ms ("
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(1000 / processingMin, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ " FPS), "
|
|
|
|
|
+ "Mean: "
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(processingMean, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ "ms ("
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(1000 / processingMean, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ " FPS), "
|
|
|
|
|
+ "Max: "
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(processingMax, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ "ms ("
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(1000 / processingMax, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ " FPS)";
|
|
|
|
|
System.out.println(processingResult);
|
|
|
|
|
String latencyResult =
|
|
|
|
|
"Latency times - "
|
|
|
|
|
+ "Min: "
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(latencyMin, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ "ms ("
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(1000 / latencyMin, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ " FPS), "
|
|
|
|
|
+ "Mean: "
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(latencyMean, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ "ms ("
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(1000 / latencyMean, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ " FPS), "
|
|
|
|
|
+ "Max: "
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(latencyMax, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ "ms ("
|
2020-06-12 21:09:47 -04:00
|
|
|
+ MathUtils.roundTo(1000 / latencyMax, 3)
|
2020-06-12 19:58:58 -04:00
|
|
|
+ " FPS)";
|
|
|
|
|
System.out.println(latencyResult);
|
|
|
|
|
}
|
|
|
|
|
}
|