Support for driver settings tab

This commit is contained in:
Omer
2019-11-01 17:01:10 +02:00
parent 7ef05e6077
commit a050dff150
5 changed files with 48 additions and 22 deletions

View File

@@ -52,7 +52,7 @@ public class Camera {
//Driver mode camera settings
public int driverExposure;
public int driverBrightness;
public boolean isDriver;
private boolean isDriver;
public Camera(String cameraName) {
this(cameraName, DEFAULT_FOV);
@@ -67,18 +67,18 @@ public class Camera {
}
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, StreamDivisor divisor) {
this(cameraName, usbCamInfo, fov, new ArrayList<>(), 0, divisor, DEFAULT_EXPOSURE, DEFAULT_BRIGHTNESS);
this(cameraName, usbCamInfo, fov, new ArrayList<>(), 0, divisor, DEFAULT_EXPOSURE, DEFAULT_BRIGHTNESS,false);
}
public Camera(String cameraName, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness) {
this(cameraName, CameraManager.AllUsbCameraInfosByName.get(cameraName), fov, pipelines, videoModeIndex, divisor, driverExposure, driverBrightness);
public Camera(String cameraName, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness,boolean isDriver) {
this(cameraName, CameraManager.AllUsbCameraInfosByName.get(cameraName), fov, pipelines, videoModeIndex, divisor, driverExposure, driverBrightness, isDriver);
}
public Camera(String cameraName, double fov, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness) {
this(cameraName, fov, new ArrayList<>(), videoModeIndex, divisor, driverExposure, driverBrightness);
public Camera(String cameraName, double fov, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness,boolean isDriver) {
this(cameraName, fov, new ArrayList<>(), videoModeIndex, divisor, driverExposure, driverBrightness,isDriver);
}
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness) {
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness,boolean isDriver) {
FOV = fov;
name = cameraName;
@@ -121,7 +121,9 @@ public class Camera {
cvSink = cs.getVideo(UsbCam);
cvSource = cs.putVideo(name, camVals.ImageWidth, camVals.ImageHeight);
isDriver = false;
//Driver mode settings
this.isDriver = isDriver;
this.driverBrightness=driverBrightness;
this.driverExposure=driverExposure;
}
@@ -228,18 +230,15 @@ public class Camera {
public void setDriverMode(boolean state)
{
Map<String,Integer> data = new HashMap<>();
isDriver=state;
if(isDriver){
UsbCam.setBrightness(driverBrightness);
UsbCam.setBrightness(driverBrightness);
UsbCam.setBrightness(driverBrightness);//We call setBrightness because it updates after 2 calls
UsbCam.setBrightness(driverBrightness);//Check it after we update to 2020 libraries
try{UsbCam.setExposureManual(driverExposure);}
catch (VideoException e)
{
System.out.println("Exposure change isnt supported");
System.out.println("Exposure change isn't supported");
}
data.put("brightness",getBrightness());
data.put("exposure",driverExposure);
}
else{
UsbCam.setBrightness(getCurrentPipeline().brightness);
@@ -247,18 +246,22 @@ public class Camera {
try{UsbCam.setExposureManual(getCurrentPipeline().exposure);}
catch (VideoException e)
{
System.out.println("Exposure change isnt supported");
System.out.println("Exposure change isn't supported");
}
data.put("brightness",getBrightness());
data.put("exposure",getCurrentPipeline().exposure);
}
ServerHandler.broadcastMessage(data);
}
public boolean getDriverMode()
{
return isDriver;
}
public int getBrightness() {
return UsbCam.getBrightness();
}
public void setBrightness(int brightness) {
if (isDriver)
driverBrightness=brightness;

View File

@@ -23,6 +23,7 @@ public class CameraDeserializer implements JsonDeserializer<Camera> {
var camName = jsonObj.get("name").getAsString();
var camNickname = jsonObj.get("nickname").getAsString();
var videoModeIndex = jsonObj.get("resolution").getAsInt();
var isDriver = jsonObj.get("isDriver").getAsBoolean();
var driverExposure = jsonObj.get("driverExposure").getAsInt();
var driverBrightness = jsonObj.get("driverBrightness").getAsInt();
var divisor = StreamDivisor.values()[jsonObj.get("streamDivisor").getAsInt()];
@@ -38,13 +39,13 @@ public class CameraDeserializer implements JsonDeserializer<Camera> {
e.printStackTrace();
}
var newCamera = actualPipelines != null ? new Camera(camName, camFOV, actualPipelines, videoModeIndex, divisor, driverExposure, driverBrightness) : new Camera(camName, camFOV, videoModeIndex, divisor, driverExposure, driverBrightness);
var newCamera = actualPipelines != null ? new Camera(camName, camFOV, actualPipelines, videoModeIndex, divisor, driverExposure, driverBrightness,isDriver) : new Camera(camName, camFOV, videoModeIndex, divisor, driverExposure, driverBrightness,isDriver);
newCamera.setNickname(camNickname != null ? camNickname : "");
return newCamera;
}
catch (NullPointerException e)
{
System.err.println("Error while reading json, value doesnt exist!");
System.err.println("Error while reading json, value doesn't exist!");
System.err.println("Try to delete the camera settings in settings/cameras/YOURCAMERA.json");
e.printStackTrace();
return null;

View File

@@ -16,6 +16,7 @@ public class CameraSerializer implements JsonSerializer<Camera> {
obj.add("pipelines", pipelines);
obj.addProperty("resolution", camera.getVideoModeIndex());
obj.add("camVideoMode", context.serialize(camera.getVideoMode()));
obj.add("isDriver",context.serialize(camera.getDriverMode()));
obj.add("driverExposure",context.serialize(camera.driverExposure));
obj.add("driverBrightness",context.serialize(camera.driverBrightness));
return obj;

View File

@@ -123,7 +123,7 @@ public class VisionProcess implements Runnable {
if (currentPipeline.orientation.equals(Orientation.Inverted)) {
Core.flip(inputImage, inputImage, -1);
}
if (ntDriverModeEntry.getBoolean(false)) {
if (camera.getDriverMode()) {
inputImage.copyTo(outputImage);
return pipelineResult;
}