mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
finished save cameras function and helper functions
This commit is contained in:
@@ -2,6 +2,7 @@ package com.chameleonvision.config;
|
||||
|
||||
import com.chameleonvision.util.ProgramDirectoryUtilities;
|
||||
import com.chameleonvision.util.FileHelper;
|
||||
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -82,4 +83,22 @@ public class ConfigManager {
|
||||
|
||||
return configList;
|
||||
}
|
||||
public static void saveCameraPipelines(String cameraName, List<CVPipelineSettings> pipelines) throws IOException {
|
||||
Path cameraFolder = Paths.get(cameraConfigPath.toString(), cameraName);
|
||||
Path filePath = Paths.get(cameraFolder.toString(), cameraName,"pipelines.json");
|
||||
FileHelper.CheckPath(cameraFolder);
|
||||
FileHelper.Serializer(filePath, pipelines);
|
||||
}
|
||||
public static void saveCameraDriverMode(String cameraName, CVPipelineSettings driverMode) throws IOException {
|
||||
Path cameraFolder = Paths.get(cameraConfigPath.toString(), cameraName);
|
||||
Path filePath = Paths.get(cameraFolder.toString(), cameraName,"driverMode.json");
|
||||
FileHelper.CheckPath(cameraFolder);
|
||||
FileHelper.Serializer(filePath, driverMode);
|
||||
}
|
||||
public static void saveCameraConfig(String cameraName, CameraConfig config) throws IOException {
|
||||
Path cameraFolder = Paths.get(cameraConfigPath.toString(), cameraName);
|
||||
Path filePath = Paths.get(cameraFolder.toString(), cameraName,"driverMode.json");
|
||||
FileHelper.CheckPath(cameraFolder);
|
||||
FileHelper.Serializer(filePath, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import edu.wpi.cscore.UsbCameraInfo;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.videoio.VideoCapture;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -114,10 +115,17 @@ public class VisionManager {
|
||||
public static void saveCameras() {
|
||||
VisionProcessesByIndex.forEach((index, process) -> {
|
||||
VisionProcess p = process.getLeft();
|
||||
String name = process.getRight();
|
||||
String cameraName = process.getRight();
|
||||
List<CVPipelineSettings> pipelines = p.getPipelines().stream().map(cvPipeline -> cvPipeline.settings).collect(Collectors.toList());
|
||||
CVPipelineSettings driverMode = p.getDriverModeSettings();
|
||||
//TODO: get camera config and serialize into folder with camera name
|
||||
CameraConfig config = CameraConfig.fromUSBCameraProcess((USBCameraProcess) p.getCamera());
|
||||
try {
|
||||
ConfigManager.saveCameraPipelines(cameraName, pipelines);
|
||||
ConfigManager.saveCameraDriverMode(cameraName, driverMode);
|
||||
ConfigManager.saveCameraConfig(cameraName, config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user