From e5c9cdf6eee302ed20a80c39149b31750cc40be2 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 19 Jul 2024 09:14:11 -0500 Subject: [PATCH] Renames, improved camera-specific settables --- .../vision/camera/CameraQuirk.java | 6 +-- .../vision/camera/QuirkyCamera.java | 8 ++-- .../USBCameras/ArduOV2311CameraSettables.java | 23 ++++++++++ .../USBCameras/GenericUSBCameraSettables.java | 14 +----- .../USBCameras/PsEyeCameraSettables.java | 44 +++++++++++++++++++ .../camera/USBCameras/USBCameraSource.java | 9 +++- .../photonvision/vision/QuirkyCameraTest.java | 2 +- 7 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/ArduOV2311CameraSettables.java create mode 100644 photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/PsEyeCameraSettables.java diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/CameraQuirk.java b/photon-core/src/main/java/org/photonvision/vision/camera/CameraQuirk.java index e069d20787..3b56c9a13a 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/CameraQuirk.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/CameraQuirk.java @@ -21,9 +21,9 @@ public enum CameraQuirk { /** Camera settable for controllable image gain */ Gain, /** Only certain discrete exposure settings work */ - LifeCam, + LifeCamControls, /** Auto-Exposure property uses 1/0, rather than 3/1 */ - OneZeroAutoExposure, + PsEyeControls, /** Cap at 100FPS for high-bandwidth cameras */ FPSCap100, /** Separate red/blue gain controls available */ @@ -42,5 +42,5 @@ public enum CameraQuirk { */ ArduOV9281, /** Dummy quirk to tell OV2311 from OV9281 */ - ArduOV2311, + ArduOV2311Controls, } diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java b/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java index f6c86fcbb1..19392c30c2 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java @@ -39,16 +39,16 @@ public class QuirkyCamera { // Mac Facetime Camera shared into Windows in Bootcamp new QuirkyCamera(-1, -1, "FaceTime HD Camera", CameraQuirk.CompletelyBroken), // Microsoft Lifecam - new QuirkyCamera(-1, -1, "LifeCam HD-3000", CameraQuirk.LifeCam), + new QuirkyCamera(-1, -1, "LifeCam HD-3000", CameraQuirk.LifeCamControls), // Microsoft Lifecam - new QuirkyCamera(-1, -1, "LifeCam Cinema (TM)", CameraQuirk.LifeCam), + new QuirkyCamera(-1, -1, "LifeCam Cinema (TM)", CameraQuirk.LifeCamControls), // PS3Eye new QuirkyCamera( 0x1415, 0x2000, CameraQuirk.Gain, CameraQuirk.FPSCap100, - CameraQuirk.OneZeroAutoExposure), + CameraQuirk.PsEyeControls), // Logitech C925-e new QuirkyCamera(0x85B, 0x46D, CameraQuirk.AdjustableFocus), // Generic arducam. Since OV2311 can't be differentiated @@ -67,7 +67,7 @@ public class QuirkyCamera { "OV2311", "OV2311", CameraQuirk.ArduCamCamera, - CameraQuirk.ArduOV2311, + CameraQuirk.ArduOV2311Controls, CameraQuirk.StickyFPS), // Arducam OV9281 new QuirkyCamera( diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/ArduOV2311CameraSettables.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/ArduOV2311CameraSettables.java new file mode 100644 index 0000000000..c05861342a --- /dev/null +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/ArduOV2311CameraSettables.java @@ -0,0 +1,23 @@ +package org.photonvision.vision.camera.USBCameras; + +import edu.wpi.first.cscore.UsbCamera; + + +import org.photonvision.common.configuration.CameraConfiguration; + +public class ArduOV2311CameraSettables extends GenericUSBCameraSettables { + + public ArduOV2311CameraSettables(CameraConfiguration configuration, UsbCamera camera) { + super(configuration, camera); + } + + @Override + protected void setUpExposureProperties() { + super.setUpExposureProperties(); + + // Property limits are incorrect + this.minExposure = 1; + this.maxExposure = 75; + } + +} diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java index e5f6cf96a6..4235c03963 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java @@ -33,8 +33,8 @@ public class GenericUSBCameraSettables extends VisionSourceSettables { protected double minExposure = 1; protected double maxExposure = 80000; - protected int PROP_AUTO_EXPOSURE_ENABLED = 3; - protected int PROP_AUTO_EXPOSURE_DISABLED = 1; + protected static final int PROP_AUTO_EXPOSURE_ENABLED = 3; + protected static final int PROP_AUTO_EXPOSURE_DISABLED = 1; protected UsbCamera camera; protected CameraConfiguration configuration; @@ -53,16 +53,6 @@ public GenericUSBCameraSettables(CameraConfiguration configuration, UsbCamera ca } } - if (configuration.cameraQuirks.hasQuirk(CameraQuirk.ArduOV2311)) { - // Property limits are incorrect - this.minExposure = 1; - this.maxExposure = 75; - } - - if (configuration.cameraQuirks.hasQuirk(CameraQuirk.OneZeroAutoExposure)) { - PROP_AUTO_EXPOSURE_ENABLED = 0; - PROP_AUTO_EXPOSURE_DISABLED = 1; - } } protected void setUpExposureProperties() { diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/PsEyeCameraSettables.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/PsEyeCameraSettables.java new file mode 100644 index 0000000000..ceacf125ff --- /dev/null +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/PsEyeCameraSettables.java @@ -0,0 +1,44 @@ +package org.photonvision.vision.camera.USBCameras; + +import edu.wpi.first.cscore.UsbCamera; + + +import org.photonvision.common.configuration.CameraConfiguration; + +public class PsEyeCameraSettables extends GenericUSBCameraSettables { + + public PsEyeCameraSettables(CameraConfiguration configuration, UsbCamera camera) { + super(configuration, camera); + } + + public void setAutoExposure(boolean cameraAutoExposure) { + logger.debug("Setting auto exposure to " + cameraAutoExposure); + + // PS Eye uses inverted 1=Disabled, 0=Enabled for auto exposure + if (!cameraAutoExposure) { + autoExposureProp.set(1); + + // Most cameras leave exposure time absolute at the last value + // from their auto exposure algorithm. + // Set it back to the exposure slider value + setExposureRaw(this.lastExposureRaw); + + } else { + autoExposureProp.set(0); + } + } + + public void setAllCamDefaults() { + // Common settings for all cameras to attempt to get their image + // as close as possible to what we want for image processing + softSet("raw_hue", 0); + softSet("raw_contrast", 32); + softSet("raw_saturation", 100); + softSet("raw_hue", -10); + softSet("raw_sharpness", 0); + softSet("white_balance_automatic", 0); + softSet("gain_automatic", 0); + } + + +} diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java index 06431db05a..0d6b02e2ab 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java @@ -113,7 +113,7 @@ private GenericUSBCameraSettables createSettables(CameraConfiguration config, Us GenericUSBCameraSettables settables; - if (quirks.hasQuirk(CameraQuirk.LifeCam)) { + if (quirks.hasQuirk(CameraQuirk.LifeCamControls)) { if(RuntimeDetector.isWindows()){ logger.debug("Using Microsoft Lifecam 3000 Windows-Specific Settables"); settables = new LifeCam3kWindowsCameraSettables(config, camera); @@ -121,7 +121,12 @@ private GenericUSBCameraSettables createSettables(CameraConfiguration config, Us logger.debug("Using Microsoft Lifecam 3000 Settables"); settables = new LifeCam3kCameraSettables(config, camera); } - + }else if (quirks.hasQuirk(CameraQuirk.PsEyeControls)){ + logger.debug("Using PlayStation Eye Camera Settables"); + settables = new PsEyeCameraSettables(config, camera); + }else if (quirks.hasQuirk(CameraQuirk.ArduOV2311Controls)){ + logger.debug("Using Arducam OV2311 Settables"); + settables = new ArduOV2311CameraSettables(config, camera); } else { logger.debug("Using Generic USB Cam Settables"); settables = new GenericUSBCameraSettables(config, camera); diff --git a/photon-core/src/test/java/org/photonvision/vision/QuirkyCameraTest.java b/photon-core/src/test/java/org/photonvision/vision/QuirkyCameraTest.java index 9b00566842..927a2cf27d 100644 --- a/photon-core/src/test/java/org/photonvision/vision/QuirkyCameraTest.java +++ b/photon-core/src/test/java/org/photonvision/vision/QuirkyCameraTest.java @@ -29,7 +29,7 @@ public void ps3EyeTest() { HashMap ps3EyeQuirks = new HashMap<>(); ps3EyeQuirks.put(CameraQuirk.Gain, true); ps3EyeQuirks.put(CameraQuirk.FPSCap100, true); - ps3EyeQuirks.put(CameraQuirk.OneZeroAutoExposure, true); + ps3EyeQuirks.put(CameraQuirk.PsEyeControls, true); for (var q : CameraQuirk.values()) { ps3EyeQuirks.putIfAbsent(q, false); }