mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Fixed usb camera bug, work on pipeline configs
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.chameleonvision.config;
|
||||
|
||||
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CVPipelineSettingsList extends List<CVPipelineSettings> {
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.chameleonvision.config;
|
||||
|
||||
import com.chameleonvision.util.JacksonHelper;
|
||||
import com.chameleonvision.vision.pipeline.CVPipeline2dSettings;
|
||||
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
||||
|
||||
import java.io.File;
|
||||
@@ -38,6 +39,11 @@ public class CameraConfig {
|
||||
CameraJsonConfig config = preliminaryConfig;
|
||||
try {
|
||||
config = JacksonHelper.deserializer(getConfigPath(), CameraJsonConfig.class);
|
||||
// if (config != null) {
|
||||
// TODO: fix for multicamera
|
||||
// boolean pathsDifferent = !(config.path != preliminaryConfig.path);
|
||||
// config = new CameraJsonConfig(config.fov, preliminaryConfig.path, config.name, config.nickname);
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
System.err.printf("Failed to load camera config: %s - using default.\n", getConfigPath().toString());
|
||||
}
|
||||
@@ -48,10 +54,8 @@ public class CameraConfig {
|
||||
List<CVPipelineSettings> pipelines = new ArrayList<>();
|
||||
try {
|
||||
var pipelineArray = JacksonHelper.deserializer(getPipelinesPath(), CVPipelineSettings[].class);
|
||||
if (pipelineArray != null) {
|
||||
pipelines = Arrays.asList(pipelineArray);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// pipelines = Arrays.asList(pipelineArray);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load camera pipelines: " + getPipelinesPath().toString());
|
||||
}
|
||||
return pipelines;
|
||||
@@ -78,7 +82,7 @@ public class CameraConfig {
|
||||
|
||||
void savePipelines(List<CVPipelineSettings> pipelines) {
|
||||
try {
|
||||
JacksonHelper.serializer(getPipelinesPath(), pipelines);
|
||||
JacksonHelper.serializer(getPipelinesPath(), pipelines.toArray());
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to save camera pipelines file: " + getConfigPath().toString());
|
||||
}
|
||||
@@ -99,8 +103,7 @@ public class CameraConfig {
|
||||
System.err.println("Failed to create camera config folder: " + getFolderPath().toString());
|
||||
}
|
||||
} catch(Exception e) {
|
||||
if(!(e instanceof java.nio.file.FileAlreadyExistsException || e instanceof java.nio.file.FileAlreadyExistsException))
|
||||
System.err.println("Failed to create camera config folder: " + getFolderPath().toString());
|
||||
System.err.println("Failed to create camera config folder: " + getFolderPath().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +121,8 @@ public class CameraConfig {
|
||||
private void checkPipelines() {
|
||||
if (!pipelinesExists()) {
|
||||
try {
|
||||
Files.createFile(getPipelinesPath());
|
||||
var sanePipeline = List.of(new CVPipeline2dSettings()).toArray();
|
||||
JacksonHelper.serializer(getPipelinesPath(), List.of(new CVPipeline2dSettings()).toArray());
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to create camera pipelines file: " + getPipelinesPath().toString());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@ public class CameraJsonConfig {
|
||||
|
||||
public static CameraJsonConfig fromUSBCameraProcess(USBCameraCapture process) {
|
||||
USBCameraProperties camProps = process.getProperties();
|
||||
return new CameraJsonConfig(camProps.getFOV(), camProps.name, camProps.path, camProps.getNickname());
|
||||
return new CameraJsonConfig(camProps.getFOV(), camProps.path, camProps.name, camProps.getNickname());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,15 @@ import java.nio.file.Path;
|
||||
public class JacksonHelper {
|
||||
private JacksonHelper() {} // no construction, utility class
|
||||
|
||||
public static void serializer(Path path, Object object) throws IOException {
|
||||
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(Object.class).build();
|
||||
public static <T> void serializer(Path path, T object) throws IOException {
|
||||
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(object.getClass()).build();
|
||||
ObjectMapper objectMapper = JsonMapper.builder().activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT).build();
|
||||
objectMapper.writerWithDefaultPrettyPrinter().writeValue(new File(path.toString()), object);
|
||||
}
|
||||
|
||||
public static <T> T deserializer(Path path, Class<T> ref) throws IOException {
|
||||
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(ref).build();
|
||||
ObjectMapper objectMapper = JsonMapper.builder().activateDefaultTyping(ptv).build();
|
||||
ObjectMapper objectMapper = JsonMapper.builder().activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT).build();
|
||||
File jsonFile = new File(path.toString());
|
||||
if (jsonFile.exists() && jsonFile.length() > 0) {
|
||||
return objectMapper.readValue(jsonFile, ref);
|
||||
|
||||
@@ -92,8 +92,7 @@ public class VisionManager {
|
||||
CameraJsonConfig cameraJsonConfig = config.cameraConfig;
|
||||
|
||||
CameraCapture camera = new USBCameraCapture(cameraJsonConfig);
|
||||
VisionProcess process = new VisionProcess(camera, cameraJsonConfig.name);
|
||||
config.pipelines.forEach(process::addPipeline);
|
||||
VisionProcess process = new VisionProcess(camera, cameraJsonConfig.name, config.pipelines);
|
||||
process.setDriverModeSettings(config.drivermode);
|
||||
visionProcesses.add(new VisionProcessManageable(i, cameraJsonConfig.name, process));
|
||||
}
|
||||
@@ -172,8 +171,12 @@ public class VisionManager {
|
||||
ConfigManager.saveCameraDriverMode(getCurrentCameraName(), driverModeSettings);
|
||||
}
|
||||
|
||||
public static List<String> getCameraResolutionList(CameraCapture capture) {
|
||||
return capture.getProperties().getVideoModes().stream().map(Helpers::VideoModeToString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<String> getCurrentCameraResolutionList() {
|
||||
return currentUIVisionProcess.getCamera().getProperties().getVideoModes().stream().map(Helpers::VideoModeToString).collect(Collectors.toList());
|
||||
return getCameraResolutionList(currentUIVisionProcess.getCamera());
|
||||
}
|
||||
|
||||
public static int getCurrentUIVisionProcessIndex() {
|
||||
|
||||
@@ -55,11 +55,18 @@ public class VisionProcess {
|
||||
private NetworkTableEntry ntValidEntry;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
VisionProcess(CameraCapture cameraCapture, String name) {
|
||||
VisionProcess(CameraCapture cameraCapture, String name, List<CVPipelineSettings> loadedPipelineSettings) {
|
||||
this.cameraCapture = cameraCapture;
|
||||
|
||||
pipelines.add(new CVPipeline2d("New Pipeline"));
|
||||
setPipeline(0, false);
|
||||
if (loadedPipelineSettings == null || loadedPipelineSettings.size() == 0) {
|
||||
pipelines.add(new CVPipeline2d("New Pipeline"));
|
||||
} else {
|
||||
for (CVPipelineSettings setting : loadedPipelineSettings) {
|
||||
addPipeline(setting);
|
||||
}
|
||||
setPipeline(0, false);
|
||||
}
|
||||
|
||||
|
||||
// Thread to put frames on the dashboard
|
||||
this.cameraStreamer = new CameraStreamer(cameraCapture, name);
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
package com.chameleonvision.web;
|
||||
|
||||
import com.chameleonvision.config.GeneralSettings;
|
||||
import com.chameleonvision.config.ConfigManager;
|
||||
import com.chameleonvision.vision.VisionManager;
|
||||
import com.chameleonvision.vision.VisionProcess;
|
||||
import com.chameleonvision.vision.camera.CameraCapture;
|
||||
import com.chameleonvision.config.ConfigManager;
|
||||
import com.chameleonvision.vision.enums.CalibrationMode;
|
||||
import com.chameleonvision.vision.pipeline.CVPipeline;
|
||||
import com.chameleonvision.vision.pipeline.CVPipeline2dSettings;
|
||||
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
||||
import com.chameleonvision.vision.enums.StreamDivisor;
|
||||
import com.chameleonvision.vision.pipeline.CVPipeline;
|
||||
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.javalin.websocket.*;
|
||||
|
||||
import io.javalin.websocket.WsBinaryMessageContext;
|
||||
import io.javalin.websocket.WsCloseContext;
|
||||
import io.javalin.websocket.WsConnectContext;
|
||||
import io.javalin.websocket.WsContext;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class SocketHandler {
|
||||
@@ -137,13 +139,13 @@ public class SocketHandler {
|
||||
switch (entry.getKey()) {
|
||||
case "exposure": {
|
||||
currentCamera.setExposure((Integer) entry.getValue());
|
||||
VisionManager.saveCurrentCameraPipelines();
|
||||
}
|
||||
case "brightness": {
|
||||
currentCamera.setBrightness((Integer) entry.getValue());
|
||||
VisionManager.saveCurrentCameraPipelines();
|
||||
}
|
||||
}
|
||||
|
||||
VisionManager.saveCurrentCameraPipelines();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user