mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-28 02:11:40 +00:00
WPI Image Test Mode (#81)
* Add camera config for calibration to test mode * Add 3D capabilities to test mode * Add resources to main for jar testmode * Refactor path utilities for test mode * Apply spotless
This commit is contained in:
@@ -18,9 +18,11 @@
|
||||
package org.photonvision;
|
||||
|
||||
import edu.wpi.cscore.CameraServerCvJNI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.photonvision.common.configuration.CameraConfiguration;
|
||||
import org.photonvision.common.configuration.ConfigManager;
|
||||
import org.photonvision.common.dataflow.networktables.NetworkTablesManager;
|
||||
import org.photonvision.common.hardware.Platform;
|
||||
@@ -28,12 +30,16 @@ import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.LogLevel;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
import org.photonvision.common.networking.NetworkManager;
|
||||
import org.photonvision.common.util.TestUtils;
|
||||
import org.photonvision.server.Server;
|
||||
import org.photonvision.vision.camera.FileVisionSource;
|
||||
import org.photonvision.vision.camera.USBCameraSource;
|
||||
import org.photonvision.vision.pipeline.CVPipelineSettings;
|
||||
import org.photonvision.vision.pipeline.ReflectivePipelineSettings;
|
||||
import org.photonvision.vision.processes.VisionModuleManager;
|
||||
import org.photonvision.vision.processes.VisionSource;
|
||||
import org.photonvision.vision.processes.VisionSourceManager;
|
||||
import org.photonvision.vision.target.TargetModel;
|
||||
|
||||
public class Main {
|
||||
public static final int DEFAULT_WEBPORT = 5800;
|
||||
@@ -79,12 +85,12 @@ public class Main {
|
||||
}
|
||||
|
||||
private static HashMap<VisionSource, List<CVPipelineSettings>> gatherSources() {
|
||||
var collectedSources = new HashMap<VisionSource, List<CVPipelineSettings>>();
|
||||
if (!isTestMode) {
|
||||
var camConfigs = ConfigManager.getInstance().getConfig().getCameraConfigurations();
|
||||
logger.info("Loaded " + camConfigs.size() + " configs from disk.");
|
||||
var sources = VisionSourceManager.loadAllSources(camConfigs.values());
|
||||
|
||||
var collectedSources = new HashMap<VisionSource, List<CVPipelineSettings>>();
|
||||
for (var src : sources) {
|
||||
var usbSrc = (USBCameraSource) src;
|
||||
collectedSources.put(usbSrc, usbSrc.configuration.pipelineSettings);
|
||||
@@ -96,11 +102,41 @@ public class Main {
|
||||
+ usbSrc.configuration.pipelineSettings.size()
|
||||
+ " pipelines");
|
||||
}
|
||||
return collectedSources;
|
||||
} else {
|
||||
// todo: test mode
|
||||
return new HashMap<>();
|
||||
var camConf2019 =
|
||||
new CameraConfiguration("WPI2019", TestUtils.getTestMode2019ImagePath().toString());
|
||||
camConf2019.FOV = TestUtils.WPI2019Image.FOV;
|
||||
camConf2019.calibration = TestUtils.get2019LifeCamCoeffs(true);
|
||||
|
||||
var pipeline2019 = new ReflectivePipelineSettings();
|
||||
pipeline2019.pipelineNickname = "CargoShip";
|
||||
pipeline2019.targetModel = TargetModel.get2019Target();
|
||||
pipeline2019.cameraCalibration = camConf2019.calibration;
|
||||
|
||||
var psList2019 = new ArrayList<CVPipelineSettings>();
|
||||
psList2019.add(pipeline2019);
|
||||
|
||||
var fvs2019 = new FileVisionSource(camConf2019);
|
||||
|
||||
var camConf2020 =
|
||||
new CameraConfiguration("WPI2020", TestUtils.getTestMode2020ImagePath().toString());
|
||||
camConf2020.FOV = TestUtils.WPI2020Image.FOV;
|
||||
camConf2020.calibration = TestUtils.get2020LifeCamCoeffs(true);
|
||||
|
||||
var pipeline2020 = new ReflectivePipelineSettings();
|
||||
pipeline2020.pipelineNickname = "OuterPort";
|
||||
pipeline2020.targetModel = TargetModel.get2020Target();
|
||||
pipeline2020.cameraCalibration = camConf2020.calibration;
|
||||
|
||||
var psList2020 = new ArrayList<CVPipelineSettings>();
|
||||
psList2020.add(pipeline2020);
|
||||
|
||||
var fvs2020 = new FileVisionSource(camConf2020);
|
||||
|
||||
collectedSources.put(fvs2019, psList2019);
|
||||
collectedSources.put(fvs2020, psList2020);
|
||||
}
|
||||
return collectedSources;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.photonvision.common.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import edu.wpi.cscore.CameraServerCvJNI;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
@@ -24,6 +25,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.highgui.HighGui;
|
||||
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
@@ -39,7 +41,9 @@ public class TestUtils {
|
||||
kCargoStraightDark48in(1.2192),
|
||||
kCargoStraightDark72in(1.8288),
|
||||
kCargoStraightDark72in_HighRes(1.8288),
|
||||
kCargoStraightDark90in(2.286);
|
||||
kCargoStraightDark90in(2.286),
|
||||
kRocketPanelAngleDark48in(1.2192),
|
||||
kRocketPanelAngleDark60in(1.524);
|
||||
|
||||
public static double FOV = 68.5;
|
||||
|
||||
@@ -130,44 +134,82 @@ public class TestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static Path getResourcesFolderPath() {
|
||||
return Path.of("src", "test", "resources").toAbsolutePath();
|
||||
private static Path getResourcesFolderPath(boolean testMode) {
|
||||
return Path.of("src", (testMode ? "main" : "test"), "resources").toAbsolutePath();
|
||||
}
|
||||
|
||||
public static Path getTestImagesPath() {
|
||||
return getResourcesFolderPath().resolve("testimages");
|
||||
public static Path getTestMode2019ImagePath() {
|
||||
return getResourcesFolderPath(true)
|
||||
.resolve("testimages")
|
||||
.resolve(WPI2019Image.kRocketPanelAngleDark60in.path);
|
||||
}
|
||||
|
||||
public static Path getCalibrationPath() {
|
||||
return getResourcesFolderPath().resolve("calibration");
|
||||
public static Path getTestMode2020ImagePath() {
|
||||
return getResourcesFolderPath(true)
|
||||
.resolve("testimages")
|
||||
.resolve(WPI2020Image.kBlueGoal_108in_Center.path);
|
||||
}
|
||||
|
||||
public static Path getPowercellPath() {
|
||||
return getTestImagesPath().resolve("polygons").resolve("powercells");
|
||||
public static Path getTestImagesPath(boolean testMode) {
|
||||
return getResourcesFolderPath(testMode).resolve("testimages");
|
||||
}
|
||||
|
||||
public static Path getWPIImagePath(WPI2020Image image) {
|
||||
return getTestImagesPath().resolve(image.path);
|
||||
public static Path getCalibrationPath(boolean testMode) {
|
||||
return getResourcesFolderPath(testMode).resolve("calibration");
|
||||
}
|
||||
|
||||
public static Path getWPIImagePath(WPI2019Image image) {
|
||||
return getTestImagesPath().resolve(image.path);
|
||||
public static Path getPowercellPath(boolean testMode) {
|
||||
return getTestImagesPath(testMode).resolve("polygons").resolve("powercells");
|
||||
}
|
||||
|
||||
public static Path getPolygonImagePath(PolygonTestImages image) {
|
||||
return getTestImagesPath().resolve(image.path);
|
||||
public static Path getWPIImagePath(WPI2020Image image, boolean testMode) {
|
||||
return getTestImagesPath(testMode).resolve(image.path);
|
||||
}
|
||||
|
||||
public static Path getPowercellImagePath(PowercellTestImages image) {
|
||||
return getPowercellPath().resolve(image.path);
|
||||
public static Path getWPIImagePath(WPI2019Image image, boolean testMode) {
|
||||
return getTestImagesPath(testMode).resolve(image.path);
|
||||
}
|
||||
|
||||
public static Path getPolygonImagePath(PolygonTestImages image, boolean testMode) {
|
||||
return getTestImagesPath(testMode).resolve(image.path);
|
||||
}
|
||||
|
||||
public static Path getPowercellImagePath(PowercellTestImages image, boolean testMode) {
|
||||
return getPowercellPath(testMode).resolve(image.path);
|
||||
}
|
||||
|
||||
public static Path getDotBoardImagesPath() {
|
||||
return getResourcesFolderPath().resolve("calibrationBoardImages");
|
||||
return getResourcesFolderPath(false).resolve("calibrationBoardImages");
|
||||
}
|
||||
|
||||
public static File getHardwareConfigJson() {
|
||||
return getResourcesFolderPath().resolve("hardware").resolve("HardwareConfig.json").toFile();
|
||||
return getResourcesFolderPath(false)
|
||||
.resolve("hardware")
|
||||
.resolve("HardwareConfig.json")
|
||||
.toFile();
|
||||
}
|
||||
|
||||
private static final String LIFECAM_240P_CAL_FILE = "lifecam240p.json";
|
||||
private static final String LIFECAM_480P_CAL_FILE = "lifecam480p.json";
|
||||
|
||||
public static CameraCalibrationCoefficients getCoeffs(String filename, boolean testMode) {
|
||||
try {
|
||||
return new ObjectMapper()
|
||||
.readValue(
|
||||
(Path.of(getCalibrationPath(testMode).toString(), filename).toFile()),
|
||||
CameraCalibrationCoefficients.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static CameraCalibrationCoefficients get2019LifeCamCoeffs(boolean testMode) {
|
||||
return getCoeffs(LIFECAM_240P_CAL_FILE, testMode);
|
||||
}
|
||||
|
||||
public static CameraCalibrationCoefficients get2020LifeCamCoeffs(boolean testMode) {
|
||||
return getCoeffs(LIFECAM_480P_CAL_FILE, testMode);
|
||||
}
|
||||
|
||||
public static void loadLibraries() {
|
||||
|
||||
@@ -33,6 +33,13 @@ public class FileVisionSource implements VisionSource {
|
||||
private final FileFrameProvider frameProvider;
|
||||
private final FileSourceSettables settables;
|
||||
|
||||
public FileVisionSource(CameraConfiguration cameraConfiguration) {
|
||||
this.cameraConfiguration = cameraConfiguration;
|
||||
frameProvider = new FileFrameProvider(cameraConfiguration.path, cameraConfiguration.FOV);
|
||||
settables =
|
||||
new FileSourceSettables(cameraConfiguration, frameProvider.get().frameStaticProperties);
|
||||
}
|
||||
|
||||
public FileVisionSource(String name, String imagePath, double fov) {
|
||||
cameraConfiguration = new CameraConfiguration(name, imagePath);
|
||||
frameProvider = new FileFrameProvider(imagePath, fov);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"resolution": {
|
||||
"width": 320.0,
|
||||
"height": 240.0
|
||||
},
|
||||
"cameraIntrinsics": {
|
||||
"rows": 3,
|
||||
"cols": 3,
|
||||
"type": 6,
|
||||
"data": [
|
||||
353.74653217742724,
|
||||
0.0,
|
||||
163.55407989211918,
|
||||
0.0,
|
||||
340.77624878700817,
|
||||
119.8945718300403,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
"cameraExtrinsics": {
|
||||
"rows": 1,
|
||||
"cols": 5,
|
||||
"type": 6,
|
||||
"data": [
|
||||
0.10322037759535845,
|
||||
-0.2890556437050186,
|
||||
0.00406400648501475,
|
||||
2.5573586808275763E-4,
|
||||
-1.462385758978924
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"resolution": {
|
||||
"width": 640.0,
|
||||
"height": 480.0
|
||||
},
|
||||
"cameraIntrinsics": {
|
||||
"rows": 3,
|
||||
"cols": 3,
|
||||
"type": 6,
|
||||
"data": [
|
||||
699.3778103158814,
|
||||
0.0,
|
||||
345.6059345433618,
|
||||
0.0,
|
||||
677.7161226393544,
|
||||
207.12741326228522,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
"cameraExtrinsics": {
|
||||
"rows": 1,
|
||||
"cols": 5,
|
||||
"type": 6,
|
||||
"data": [
|
||||
0.14382207979312617,
|
||||
-0.9851192814987014,
|
||||
-0.018168751047242335,
|
||||
0.011034504043795105,
|
||||
1.9833437176538498
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user