001/* 002 * Copyright (C) Photon Vision. 003 * 004 * This program is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package org.photonvision.vision.camera.USBCameras; 019 020import edu.wpi.first.cscore.UsbCamera; 021import edu.wpi.first.cscore.VideoException; 022import edu.wpi.first.math.MathUtil; 023import org.photonvision.common.configuration.CameraConfiguration; 024 025public class LifeCam3kWindowsCameraSettables extends GenericUSBCameraSettables { 026 public LifeCam3kWindowsCameraSettables(CameraConfiguration configuration, UsbCamera camera) { 027 super(configuration, camera); 028 } 029 030 @Override 031 protected void setUpExposureProperties() { 032 autoExposureProp = null; // Not Used 033 exposureAbsProp = null; // Not Used 034 035 // We'll fallback on cscore's implementation for windows lifecam 036 this.minExposure = 0; 037 this.maxExposure = 100; 038 } 039 040 @Override 041 public void setExposureRaw(double exposureRaw) { 042 if (exposureRaw >= 0.0) { 043 try { 044 int propVal = (int) MathUtil.clamp(exposureRaw, minExposure, maxExposure); 045 046 // exposureAbsProp.set(propVal); 047 camera.setExposureManual(propVal); 048 049 this.lastExposureRaw = exposureRaw; 050 051 // Lifecam requires setting brightness again after exposure 052 // And it requires setting it twice, ensuring the value is different 053 // This camera is very bork. 054 if (lastBrightness >= 0) { 055 setBrightness(lastBrightness - 1); 056 } 057 058 } catch (VideoException e) { 059 logger.error("Failed to set camera exposure!", e); 060 } 061 } 062 } 063 064 @Override 065 public void setAutoExposure(boolean cameraAutoExposure) { 066 logger.debug("Setting auto exposure to " + cameraAutoExposure); 067 068 if (!cameraAutoExposure) { 069 // Most cameras leave exposure time absolute at the last value from their AE 070 // algorithm. 071 // Set it back to the exposure slider value 072 camera.setExposureManual((int) this.lastExposureRaw); 073 } else { 074 camera.setExposureAuto(); 075 } 076 } 077 078 @Override 079 public void setAllCamDefaults() { 080 // Common settings for all cameras to attempt to get their image 081 // as close as possible to what we want for image processing 082 softSet("raw_Contrast", 5); 083 softSet("raw_Saturation", 85); 084 softSet("raw_Sharpness", 25); 085 softSet("WhiteBalance", 4000); 086 } 087}