mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Merge branch 'dev' of https://github.com/chameleon-vision/Chameleon-Vision into dev
This commit is contained in:
@@ -32,6 +32,6 @@ public class CameraJsonConfig {
|
||||
|
||||
public static CameraJsonConfig fromUSBCameraProcess(USBCameraCapture process) {
|
||||
USBCameraProperties camProps = process.getProperties();
|
||||
return new CameraJsonConfig(camProps.FOV, camProps.name, camProps.path, camProps.getNickname());
|
||||
return new CameraJsonConfig(camProps.getFOV(), camProps.name, camProps.path, camProps.getNickname());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,18 +27,20 @@ public class CameraStreamer {
|
||||
}
|
||||
|
||||
public void setDivisor(StreamDivisor newDivisor, boolean updateUI) {
|
||||
this.divisor = newDivisor;
|
||||
var camValues = cameraCapture.getProperties();
|
||||
var newWidth = camValues.getStaticProperties().imageWidth / newDivisor.value;
|
||||
var newHeight = camValues.getStaticProperties().imageHeight / newDivisor.value;
|
||||
synchronized (streamBufferLock) {
|
||||
this.streamBuffer = new Mat(newWidth, newHeight, CvType.CV_8UC3);
|
||||
this.cvSource = CameraServer.getInstance().putVideo(this.name,
|
||||
cameraCapture.getProperties().getStaticProperties().imageWidth / divisor.value,
|
||||
cameraCapture.getProperties().getStaticProperties().imageHeight / divisor.value);
|
||||
}
|
||||
if (updateUI) {
|
||||
SocketHandler.sendFullSettings();
|
||||
if (divisor != newDivisor) {
|
||||
this.divisor = newDivisor;
|
||||
var camValues = cameraCapture.getProperties();
|
||||
var newWidth = camValues.getStaticProperties().imageWidth / newDivisor.value;
|
||||
var newHeight = camValues.getStaticProperties().imageHeight / newDivisor.value;
|
||||
synchronized (streamBufferLock) {
|
||||
this.streamBuffer = new Mat(newWidth, newHeight, CvType.CV_8UC3);
|
||||
this.cvSource = CameraServer.getInstance().putVideo(this.name,
|
||||
cameraCapture.getProperties().getStaticProperties().imageWidth / divisor.value,
|
||||
cameraCapture.getProperties().getStaticProperties().imageHeight / divisor.value);
|
||||
}
|
||||
if (updateUI) {
|
||||
SocketHandler.sendFullSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class USBCameraProperties extends CaptureProperties {
|
||||
public final boolean isPS3Eye;
|
||||
|
||||
private String nickname;
|
||||
public double FOV;
|
||||
private double FOV;
|
||||
|
||||
USBCameraProperties(UsbCamera baseCamera, CameraJsonConfig config) {
|
||||
FOV = config.fov;
|
||||
@@ -67,6 +67,15 @@ public class USBCameraProperties extends CaptureProperties {
|
||||
videoModes = filterVideoModes(baseCamera.enumerateVideoModes());
|
||||
}
|
||||
|
||||
public void setFOV(double FOV) {
|
||||
this.FOV = FOV;
|
||||
staticProperties = new CaptureStaticProperties(staticProperties.imageWidth, staticProperties.imageHeight, FOV);
|
||||
}
|
||||
|
||||
public double getFOV() {
|
||||
return FOV;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
||||
totalPipelineTimeNanos += collect2dTargetsResult.getRight();
|
||||
|
||||
// takes pair of (Mat of original camera image (8UC3), Mat of HSV thresholded image(8UC1))
|
||||
Pair<Mat, Long> outputMatResult = outputMatPipe.run(Pair.of(rawCameraMat, hsvResult.getLeft()));
|
||||
Pair<Mat, Long> outputMatResult = outputMatPipe.run(Pair.of(rotateFlipResult.getLeft(), hsvResult.getLeft()));
|
||||
totalPipelineTimeNanos += outputMatResult.getRight();
|
||||
|
||||
// takes pair of (Mat to draw on, List<RotatedRect> of sorted contours)
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GroupContoursPipe implements Pipe<List<MatOfPoint>, List<RotatedRec
|
||||
|
||||
groupedContours.clear();
|
||||
|
||||
if (input.size() > 0) {
|
||||
if (input.size() > (group.equals(TargetGroup.Single) ? 0 : 1)) {
|
||||
|
||||
List<MatOfPoint> sorted = new ArrayList<>(input);
|
||||
sorted.sort(sortByMomentsX);
|
||||
@@ -88,7 +88,6 @@ public class GroupContoursPipe implements Pipe<List<MatOfPoint>, List<RotatedRec
|
||||
groupedContours.add(rect);
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
System.err.println("GroupContours: WTF");
|
||||
finalContourList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.chameleonvision.web;
|
||||
|
||||
import com.chameleonvision.config.ConfigManager;
|
||||
import com.chameleonvision.network.NetworkIPMode;
|
||||
import com.chameleonvision.vision.VisionManager;
|
||||
import com.chameleonvision.vision.VisionProcess;
|
||||
import com.chameleonvision.vision.camera.CameraCapture;
|
||||
import com.chameleonvision.vision.enums.StreamDivisor;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class RequestHandler {
|
||||
|
||||
public static void onGeneralSettings(Context ctx) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
Map map = objectMapper.readValue(ctx.body(), Map.class);
|
||||
|
||||
// TODO: change to function, to restart NetworkTables
|
||||
ConfigManager.settings.teamNumber = (int) map.get("teamNumber");
|
||||
|
||||
ConfigManager.settings.connectionType = NetworkIPMode.values()[(int) map.get("connectionType")];
|
||||
ConfigManager.settings.ip = (String) map.get("ip");
|
||||
ConfigManager.settings.netmask = (String) map.get("netmask");
|
||||
ConfigManager.settings.gateway = (String) map.get("gateway");
|
||||
ConfigManager.settings.hostname = (String) map.get("hostname");
|
||||
ConfigManager.saveGeneralSettings();
|
||||
SocketHandler.sendFullSettings();
|
||||
ctx.status(200);
|
||||
} catch (JsonProcessingException e) {
|
||||
ctx.status(500);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onCameraSettings(Context ctx) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
Map camSettings = objectMapper.readValue(ctx.body(), Map.class);
|
||||
|
||||
VisionProcess currentVisionProcess = VisionManager.getCurrentUIVisionProcess();
|
||||
CameraCapture currentCamera = currentVisionProcess.getCamera();
|
||||
|
||||
Number newFOV = (Number) camSettings.get("fov");
|
||||
Integer newStreamDivisor = (Integer) camSettings.get("streamDivisor");
|
||||
Integer newResolution = (Integer) camSettings.get("resolution");
|
||||
|
||||
currentCamera.getProperties().setFOV((double) newFOV);
|
||||
|
||||
currentVisionProcess.cameraStreamer.setDivisor(StreamDivisor.values()[newStreamDivisor], true);
|
||||
|
||||
// TODO: Video Mode Index!!!!
|
||||
// var currentResolutionIndex = curCam.getVideoModeIndex();
|
||||
// if (currentResolutionIndex != newResolution) {
|
||||
// curCam.setCamVideoMode(newResolution, true);
|
||||
// }
|
||||
|
||||
VisionManager.saveAllCameras();
|
||||
SocketHandler.sendFullSettings();
|
||||
ctx.status(200);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
ctx.status(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.chameleonvision.web;
|
||||
|
||||
import com.chameleonvision.network.NetworkIPMode;
|
||||
import com.chameleonvision.settings.GeneralSettings;
|
||||
import com.chameleonvision.settings.SettingsManager;
|
||||
import com.chameleonvision.vision.camera.CameraException;
|
||||
import com.chameleonvision.vision.camera.CameraManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Requesthandler {
|
||||
|
||||
public static void onGeneralSettings(Context ctx) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
Map map = objectMapper.readValue(ctx.body(), Map.class);
|
||||
SettingsManager.GeneralSettings.teamNumber = (int) map.get("teamNumber");
|
||||
SettingsManager.GeneralSettings.connectionType = NetworkIPMode.values()[(int) map.get("connectionType")];
|
||||
SettingsManager.GeneralSettings.ip = (String) map.get("ip");
|
||||
SettingsManager.GeneralSettings.netmask = (String) map.get("netmask");
|
||||
SettingsManager.GeneralSettings.gateway = (String) map.get("gateway");
|
||||
SettingsManager.GeneralSettings.hostname = (String) map.get("hostname");
|
||||
SettingsManager.saveSettings();
|
||||
SocketHandler.sendFullSettings();
|
||||
ctx.status(200);
|
||||
} catch (JsonProcessingException e) {
|
||||
ctx.status(500);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onCameraSettings(Context ctx) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
Map camSettings = objectMapper.readValue(ctx.body(), Map.class);
|
||||
var curCam = CameraManager.getCurrentCamera();
|
||||
|
||||
Number newFOV = (Number) camSettings.get("fov");
|
||||
Integer newStreamDivisor = (Integer) camSettings.get("streamDivisor");
|
||||
Integer newResolution = (Integer) camSettings.get("resolution");
|
||||
|
||||
curCam.setFOV(newFOV);
|
||||
|
||||
var currentStreamDivisorOrdinal = curCam.getStreamDivisor().ordinal();
|
||||
if (currentStreamDivisorOrdinal != newStreamDivisor) {
|
||||
curCam.setStreamDivisor(newStreamDivisor, true);
|
||||
}
|
||||
|
||||
var currentResolutionIndex = curCam.getVideoModeIndex();
|
||||
if (currentResolutionIndex != newResolution) {
|
||||
curCam.setCamVideoMode(newResolution, true);
|
||||
}
|
||||
|
||||
CameraManager.saveCameras();
|
||||
SocketHandler.sendFullSettings();
|
||||
ctx.status(200);
|
||||
} catch (JsonProcessingException | CameraException e) {
|
||||
e.printStackTrace();
|
||||
ctx.status(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ public class Server {
|
||||
socketHandler.onBinaryMessage(ctx);
|
||||
});
|
||||
});
|
||||
app.post("/api/settings/general", Requesthandler::onGeneralSettings);
|
||||
app.post("/api/settings/camera", Requesthandler::onCameraSettings);
|
||||
app.post("/api/settings/general", RequestHandler::onGeneralSettings);
|
||||
app.post("/api/settings/camera", RequestHandler::onCameraSettings);
|
||||
app.start(port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class SocketHandler {
|
||||
HashMap<String, Object> tmp = new HashMap<>();
|
||||
VisionProcess currentVisionProcess = VisionManager.getCurrentUIVisionProcess();
|
||||
CameraCapture currentCamera = VisionManager.getCurrentUIVisionProcess().getCamera();
|
||||
tmp.put("fov", currentCamera.getProperties().FOV);
|
||||
tmp.put("fov", currentCamera.getProperties().getFOV());
|
||||
tmp.put("streamDivisor", currentVisionProcess.cameraStreamer.getDivisor().ordinal());
|
||||
// TODO: (HIGH) get videomode index!
|
||||
// tmp.put("resolution", currentCamera.getVideoModeIndex());
|
||||
|
||||
Reference in New Issue
Block a user