mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-06 03:31: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;
|
package com.chameleonvision.config;
|
||||||
|
|
||||||
import com.chameleonvision.util.JacksonHelper;
|
import com.chameleonvision.util.JacksonHelper;
|
||||||
|
import com.chameleonvision.vision.pipeline.CVPipeline2dSettings;
|
||||||
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -38,6 +39,11 @@ public class CameraConfig {
|
|||||||
CameraJsonConfig config = preliminaryConfig;
|
CameraJsonConfig config = preliminaryConfig;
|
||||||
try {
|
try {
|
||||||
config = JacksonHelper.deserializer(getConfigPath(), CameraJsonConfig.class);
|
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) {
|
} catch (IOException e) {
|
||||||
System.err.printf("Failed to load camera config: %s - using default.\n", getConfigPath().toString());
|
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<>();
|
List<CVPipelineSettings> pipelines = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
var pipelineArray = JacksonHelper.deserializer(getPipelinesPath(), CVPipelineSettings[].class);
|
var pipelineArray = JacksonHelper.deserializer(getPipelinesPath(), CVPipelineSettings[].class);
|
||||||
if (pipelineArray != null) {
|
// pipelines = Arrays.asList(pipelineArray);
|
||||||
pipelines = Arrays.asList(pipelineArray);
|
} catch (Exception e) {
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("Failed to load camera pipelines: " + getPipelinesPath().toString());
|
System.err.println("Failed to load camera pipelines: " + getPipelinesPath().toString());
|
||||||
}
|
}
|
||||||
return pipelines;
|
return pipelines;
|
||||||
@@ -78,7 +82,7 @@ public class CameraConfig {
|
|||||||
|
|
||||||
void savePipelines(List<CVPipelineSettings> pipelines) {
|
void savePipelines(List<CVPipelineSettings> pipelines) {
|
||||||
try {
|
try {
|
||||||
JacksonHelper.serializer(getPipelinesPath(), pipelines);
|
JacksonHelper.serializer(getPipelinesPath(), pipelines.toArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Failed to save camera pipelines file: " + getConfigPath().toString());
|
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());
|
System.err.println("Failed to create camera config folder: " + getFolderPath().toString());
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} 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() {
|
private void checkPipelines() {
|
||||||
if (!pipelinesExists()) {
|
if (!pipelinesExists()) {
|
||||||
try {
|
try {
|
||||||
Files.createFile(getPipelinesPath());
|
var sanePipeline = List.of(new CVPipeline2dSettings()).toArray();
|
||||||
|
JacksonHelper.serializer(getPipelinesPath(), List.of(new CVPipeline2dSettings()).toArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Failed to create camera pipelines file: " + getPipelinesPath().toString());
|
System.err.println("Failed to create camera pipelines file: " + getPipelinesPath().toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ public class CameraJsonConfig {
|
|||||||
|
|
||||||
public static CameraJsonConfig fromUSBCameraProcess(USBCameraCapture process) {
|
public static CameraJsonConfig fromUSBCameraProcess(USBCameraCapture process) {
|
||||||
USBCameraProperties camProps = process.getProperties();
|
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 {
|
public class JacksonHelper {
|
||||||
private JacksonHelper() {} // no construction, utility class
|
private JacksonHelper() {} // no construction, utility class
|
||||||
|
|
||||||
public static void serializer(Path path, Object object) throws IOException {
|
public static <T> void serializer(Path path, T object) throws IOException {
|
||||||
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(Object.class).build();
|
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(object.getClass()).build();
|
||||||
ObjectMapper objectMapper = JsonMapper.builder().activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT).build();
|
ObjectMapper objectMapper = JsonMapper.builder().activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT).build();
|
||||||
objectMapper.writerWithDefaultPrettyPrinter().writeValue(new File(path.toString()), object);
|
objectMapper.writerWithDefaultPrettyPrinter().writeValue(new File(path.toString()), object);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T deserializer(Path path, Class<T> ref) throws IOException {
|
public static <T> T deserializer(Path path, Class<T> ref) throws IOException {
|
||||||
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfBaseType(ref).build();
|
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());
|
File jsonFile = new File(path.toString());
|
||||||
if (jsonFile.exists() && jsonFile.length() > 0) {
|
if (jsonFile.exists() && jsonFile.length() > 0) {
|
||||||
return objectMapper.readValue(jsonFile, ref);
|
return objectMapper.readValue(jsonFile, ref);
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ public class VisionManager {
|
|||||||
CameraJsonConfig cameraJsonConfig = config.cameraConfig;
|
CameraJsonConfig cameraJsonConfig = config.cameraConfig;
|
||||||
|
|
||||||
CameraCapture camera = new USBCameraCapture(cameraJsonConfig);
|
CameraCapture camera = new USBCameraCapture(cameraJsonConfig);
|
||||||
VisionProcess process = new VisionProcess(camera, cameraJsonConfig.name);
|
VisionProcess process = new VisionProcess(camera, cameraJsonConfig.name, config.pipelines);
|
||||||
config.pipelines.forEach(process::addPipeline);
|
|
||||||
process.setDriverModeSettings(config.drivermode);
|
process.setDriverModeSettings(config.drivermode);
|
||||||
visionProcesses.add(new VisionProcessManageable(i, cameraJsonConfig.name, process));
|
visionProcesses.add(new VisionProcessManageable(i, cameraJsonConfig.name, process));
|
||||||
}
|
}
|
||||||
@@ -172,8 +171,12 @@ public class VisionManager {
|
|||||||
ConfigManager.saveCameraDriverMode(getCurrentCameraName(), driverModeSettings);
|
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() {
|
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() {
|
public static int getCurrentUIVisionProcessIndex() {
|
||||||
|
|||||||
@@ -55,11 +55,18 @@ public class VisionProcess {
|
|||||||
private NetworkTableEntry ntValidEntry;
|
private NetworkTableEntry ntValidEntry;
|
||||||
private ObjectMapper objectMapper = new ObjectMapper();
|
private ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
VisionProcess(CameraCapture cameraCapture, String name) {
|
VisionProcess(CameraCapture cameraCapture, String name, List<CVPipelineSettings> loadedPipelineSettings) {
|
||||||
this.cameraCapture = cameraCapture;
|
this.cameraCapture = cameraCapture;
|
||||||
|
|
||||||
pipelines.add(new CVPipeline2d("New Pipeline"));
|
if (loadedPipelineSettings == null || loadedPipelineSettings.size() == 0) {
|
||||||
setPipeline(0, false);
|
pipelines.add(new CVPipeline2d("New Pipeline"));
|
||||||
|
} else {
|
||||||
|
for (CVPipelineSettings setting : loadedPipelineSettings) {
|
||||||
|
addPipeline(setting);
|
||||||
|
}
|
||||||
|
setPipeline(0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Thread to put frames on the dashboard
|
// Thread to put frames on the dashboard
|
||||||
this.cameraStreamer = new CameraStreamer(cameraCapture, name);
|
this.cameraStreamer = new CameraStreamer(cameraCapture, name);
|
||||||
|
|||||||
@@ -1,26 +1,28 @@
|
|||||||
package com.chameleonvision.web;
|
package com.chameleonvision.web;
|
||||||
|
|
||||||
import com.chameleonvision.config.GeneralSettings;
|
import com.chameleonvision.config.ConfigManager;
|
||||||
import com.chameleonvision.vision.VisionManager;
|
import com.chameleonvision.vision.VisionManager;
|
||||||
import com.chameleonvision.vision.VisionProcess;
|
import com.chameleonvision.vision.VisionProcess;
|
||||||
import com.chameleonvision.vision.camera.CameraCapture;
|
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.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.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
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.apache.commons.lang3.ArrayUtils;
|
||||||
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.ByteBuffer;
|
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 {
|
public class SocketHandler {
|
||||||
@@ -137,13 +139,13 @@ public class SocketHandler {
|
|||||||
switch (entry.getKey()) {
|
switch (entry.getKey()) {
|
||||||
case "exposure": {
|
case "exposure": {
|
||||||
currentCamera.setExposure((Integer) entry.getValue());
|
currentCamera.setExposure((Integer) entry.getValue());
|
||||||
VisionManager.saveCurrentCameraPipelines();
|
|
||||||
}
|
}
|
||||||
case "brightness": {
|
case "brightness": {
|
||||||
currentCamera.setBrightness((Integer) entry.getValue());
|
currentCamera.setBrightness((Integer) entry.getValue());
|
||||||
VisionManager.saveCurrentCameraPipelines();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VisionManager.saveCurrentCameraPipelines();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user