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 c8abc68e21..1b8128df20 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 @@ -1,5 +1,10 @@ package org.photonvision.vision.camera.USBCameras; +import edu.wpi.first.cscore.UsbCamera; +import edu.wpi.first.cscore.VideoException; +import edu.wpi.first.cscore.VideoMode; +import edu.wpi.first.cscore.VideoProperty; +import edu.wpi.first.util.PixelFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -7,19 +12,12 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; - import org.photonvision.common.configuration.CameraConfiguration; import org.photonvision.common.configuration.ConfigManager; import org.photonvision.common.util.math.MathUtils; import org.photonvision.vision.camera.CameraQuirk; import org.photonvision.vision.processes.VisionSourceSettables; -import edu.wpi.first.cscore.UsbCamera; -import edu.wpi.first.cscore.VideoException; -import edu.wpi.first.cscore.VideoMode; -import edu.wpi.first.cscore.VideoProperty; -import edu.wpi.first.util.PixelFormat; - public class GenericUSBCameraSettables extends VisionSourceSettables { // We need to remember the last exposure set when exiting // auto exposure mode so we can restore it @@ -42,8 +40,7 @@ public class GenericUSBCameraSettables extends VisionSourceSettables { protected CameraConfiguration configuration; /** - * Forgiving "set this property" action. Produces a debug message but skips - * properties if they + * Forgiving "set this property" action. Produces a debug message but skips properties if they * aren't supported Errors if the property exists but the set fails. * * @param property @@ -63,8 +60,7 @@ protected void softSet(String property, int value) { } /** - * Returns the first property with a name in the list. Useful to find gandolf - * property that goes + * Returns the first property with a name in the list. Useful to find gandolf property that goes * by many names in different os/releases/whatever * * @param options @@ -92,10 +88,12 @@ protected Optional findProperty(String... options) { return Optional.ofNullable(retProp); } - protected void setUpExposureProperties(){ + protected void setUpExposureProperties() { // Photonvision needs to be able to control absolute exposure. Make sure we can // first. - var expProp = findProperty("raw_exposure_absolute", "raw_exposure_time_absolute", "exposure", "raw_Exposure"); + var expProp = + findProperty( + "raw_exposure_absolute", "raw_exposure_time_absolute", "exposure", "raw_Exposure"); // Photonvision needs to be able to control auto exposure. Make sure we can // first. @@ -136,7 +134,6 @@ public GenericUSBCameraSettables(CameraConfiguration configuration, UsbCamera ca PROP_AUTO_EXPOSURE_ENABLED = 0; PROP_AUTO_EXPOSURE_DISABLED = 1; } - } public void setAllCamDefaults() { @@ -198,10 +195,10 @@ public void setExposureRaw(double exposureRaw) { int propVal = (int) MathUtils.limit(exposureRaw, minExposure, maxExposure); - //if (configuration.cameraQuirks.hasQuirk(CameraQuirk.LifeCamExposure)) { + // if (configuration.cameraQuirks.hasQuirk(CameraQuirk.LifeCamExposure)) { // // Lifecam only allows certain settings for exposure // propVal = MathUtils.quantize(propVal, CameraQuirkConstants.LifecamAllowableExposures); - //} + // } logger.debug( "Setting property " @@ -296,14 +293,16 @@ public HashMap getAllVideoModes() { } // Sort by resolution - var sortedList = videoModesList.stream() - .distinct() // remove redundant video mode entries - .sorted(((a, b) -> (b.width + b.height) - (a.width + a.height))) - .collect(Collectors.toList()); + var sortedList = + videoModesList.stream() + .distinct() // remove redundant video mode entries + .sorted(((a, b) -> (b.width + b.height) - (a.width + a.height))) + .collect(Collectors.toList()); Collections.reverse(sortedList); // On vendor cameras, respect blacklisted indices - var indexBlacklist = ConfigManager.getInstance().getConfig().getHardwareConfig().blacklistedResIndices; + var indexBlacklist = + ConfigManager.getInstance().getConfig().getHardwareConfig().blacklistedResIndices; for (int badIdx : indexBlacklist) { sortedList.remove(badIdx); } diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSource.java index f09e23f313..6736212487 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSource.java @@ -23,7 +23,6 @@ import edu.wpi.first.cscore.VideoException; import edu.wpi.first.cscore.VideoProperty; import edu.wpi.first.util.RuntimeDetector; - import java.util.*; import org.photonvision.common.configuration.CameraConfiguration; import org.photonvision.common.logging.LogGroup; @@ -42,7 +41,6 @@ public class GenericUSBCameraSource extends VisionSource { protected FrameProvider usbFrameProvider; private final CvSink cvSink; - public GenericUSBCameraSource(CameraConfiguration config) { super(config); @@ -72,8 +70,7 @@ public GenericUSBCameraSource(CameraConfiguration config) { // in printCameraProperaties(); - var cameraBroken = - getCameraConfiguration().cameraQuirks.hasQuirk(CameraQuirk.CompletelyBroken); + var cameraBroken = getCameraConfiguration().cameraQuirks.hasQuirk(CameraQuirk.CompletelyBroken); if (cameraBroken) { // Known issues - Disable this camera @@ -98,24 +95,24 @@ public GenericUSBCameraSource(CameraConfiguration config) { // Functional camera, set up the frame provider and configure defaults usbFrameProvider = new USBFrameProvider(cvSink, settables); settables.setAllCamDefaults(); - } } } /** * Factory for making appropriate settables + * * @param config * @param camera * @return */ - private GenericUSBCameraSettables createSettables(CameraConfiguration config, UsbCamera camera){ + private GenericUSBCameraSettables createSettables(CameraConfiguration config, UsbCamera camera) { var quirks = getCameraConfiguration().cameraQuirks; GenericUSBCameraSettables settables; - if(quirks.hasQuirk(CameraQuirk.LifeCamExposure) && RuntimeDetector.isWindows()){ + if (quirks.hasQuirk(CameraQuirk.LifeCamExposure) && RuntimeDetector.isWindows()) { logger.debug("Using Microsoft Lifecam 3000 Windows-Specific Settables"); settables = new LifeCam3kWindowsCameraSettables(config, camera); } else { @@ -126,10 +123,8 @@ private GenericUSBCameraSettables createSettables(CameraConfiguration config, Us settables.setUpExposureProperties(); return settables; - } - private void printCameraProperaties() { VideoProperty[] cameraProperties = null; try { @@ -176,7 +171,6 @@ public VisionSourceSettables getSettables() { return this.settables; } - @Override public boolean isVendorCamera() { return false; // Vendors do not supply USB Cameras diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/LifeCam3kWindowsCameraSettables.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/LifeCam3kWindowsCameraSettables.java index 425acf368f..fcfd559b29 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/LifeCam3kWindowsCameraSettables.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/LifeCam3kWindowsCameraSettables.java @@ -1,10 +1,9 @@ package org.photonvision.vision.camera.USBCameras; -import org.photonvision.common.configuration.CameraConfiguration; -import org.photonvision.common.util.math.MathUtils; import edu.wpi.first.cscore.UsbCamera; import edu.wpi.first.cscore.VideoException; - +import org.photonvision.common.configuration.CameraConfiguration; +import org.photonvision.common.util.math.MathUtils; public class LifeCam3kWindowsCameraSettables extends GenericUSBCameraSettables { @@ -17,9 +16,9 @@ public LifeCam3kWindowsCameraSettables(CameraConfiguration configuration, UsbCam } @Override - protected void setUpExposureProperties(){ + protected void setUpExposureProperties() { - autoExposureProp = null; //Not Used + autoExposureProp = null; // Not Used exposureAbsProp = camera.getProperty("raw_Exposure"); this.minExposure = exposureAbsProp.getMin(); @@ -54,7 +53,6 @@ public void setExposureRaw(double exposureRaw) { if (lastBrightness >= 0) { setBrightness(lastBrightness - 1); } - } catch (VideoException e) { logger.error("Failed to set camera exposure!", e); @@ -82,10 +80,9 @@ public void setAutoExposure(boolean cameraAutoExposure) { 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_Contrast", 5); - softSet("raw_Saturation", 85); - softSet("raw_Sharpness", 25); - softSet("WhiteBalance", 4000); + softSet("raw_Contrast", 5); + softSet("raw_Saturation", 85); + softSet("raw_Sharpness", 25); + softSet("WhiteBalance", 4000); } - } diff --git a/photon-core/src/test/java/org/photonvision/vision/processes/MockUsbCameraSource.java b/photon-core/src/test/java/org/photonvision/vision/processes/MockUsbCameraSource.java index ebf06e090b..478efd80d9 100644 --- a/photon-core/src/test/java/org/photonvision/vision/processes/MockUsbCameraSource.java +++ b/photon-core/src/test/java/org/photonvision/vision/processes/MockUsbCameraSource.java @@ -17,6 +17,7 @@ package org.photonvision.vision.processes; +import edu.wpi.first.cscore.UsbCamera; import org.photonvision.common.configuration.CameraConfiguration; import org.photonvision.common.util.TestUtils; import org.photonvision.vision.camera.QuirkyCamera; @@ -24,8 +25,6 @@ import org.photonvision.vision.camera.USBCameras.GenericUSBCameraSource; import org.photonvision.vision.frame.provider.FileFrameProvider; -import edu.wpi.first.cscore.UsbCamera; - public class MockUsbCameraSource extends GenericUSBCameraSource { /** Used for unit tests to better simulate a usb camera without a camera being present. */ public MockUsbCameraSource(CameraConfiguration config, int pid, int vid) {