Skip to content

Commit

Permalink
Bugfixes. I think we're finally working acceptably with lifecams on w…
Browse files Browse the repository at this point in the history
…indows and linux
  • Loading branch information
gerth2 committed Jul 19, 2024
1 parent 909cef7 commit 4a15f27
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ public class GenericUSBCameraSettables extends VisionSourceSettables {
protected UsbCamera camera;
protected CameraConfiguration configuration;

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");

// Photonvision needs to be able to control auto exposure. Make sure we can
// first.
var autoExpProp = findProperty("exposure_auto", "auto_exposure");

exposureAbsProp = expProp.get();
autoExposureProp = autoExpProp.get();
this.minExposure = exposureAbsProp.getMin();
this.maxExposure = exposureAbsProp.getMax();
}

public GenericUSBCameraSettables(CameraConfiguration configuration, UsbCamera camera) {
super(configuration);

Expand All @@ -82,6 +65,23 @@ public GenericUSBCameraSettables(CameraConfiguration configuration, UsbCamera ca
}
}

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");

// Photonvision needs to be able to control auto exposure. Make sure we can
// first.
var autoExpProp = findProperty("exposure_auto", "auto_exposure");

exposureAbsProp = expProp.get();
autoExposureProp = autoExpProp.get();
this.minExposure = exposureAbsProp.getMin();
this.maxExposure = exposureAbsProp.getMax();
}

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
Expand All @@ -105,7 +105,7 @@ public void setAutoExposure(boolean cameraAutoExposure) {
softSet("white_balance_auto_preset", 2); // Auto white-balance disabled
softSet("white_balance_automatic", 0);
softSet("white_balance_temperature", 4000);
autoExposureProp.set(PROP_AUTO_EXPOSURE_ENABLED);
autoExposureProp.set(PROP_AUTO_EXPOSURE_DISABLED);

// Most cameras leave exposure time absolute at the last value from their AE
// algorithm.
Expand All @@ -119,7 +119,7 @@ public void setAutoExposure(boolean cameraAutoExposure) {
softSet("iso_sensitivity", 1); // Manual ISO adjustment by default
softSet("white_balance_auto_preset", 1); // Auto white-balance enabled
softSet("white_balance_automatic", 1);
autoExposureProp.set(PROP_AUTO_EXPOSURE_DISABLED);
autoExposureProp.set(PROP_AUTO_EXPOSURE_ENABLED);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ protected void setUpExposureProperties() {
autoExposureProp = findProperty("exposure_auto", "auto_exposure").get();
exposureAbsProp = findProperty("raw_exposure_time_absolute", "raw_exposure_absolute").get();

this.minExposure = 1;
this.maxExposure = 700;
this.minExposure = exposureAbsProp.getMin();
this.maxExposure = exposureAbsProp.getMax();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

public class LifeCam3kWindowsCameraSettables extends GenericUSBCameraSettables {

private static int[] allowableExposures = {
5, 10, 20, 39, 78, 156, 312, 625, 1250, 2500, 5000, 10000, 20000
};

public LifeCam3kWindowsCameraSettables(CameraConfiguration configuration, UsbCamera camera) {
super(configuration, camera);
}
Expand All @@ -19,10 +15,11 @@ public LifeCam3kWindowsCameraSettables(CameraConfiguration configuration, UsbCam
protected void setUpExposureProperties() {

autoExposureProp = null; // Not Used
exposureAbsProp = null; //Not Used

exposureAbsProp = camera.getProperty("raw_Exposure");
this.minExposure = exposureAbsProp.getMin();
this.maxExposure = exposureAbsProp.getMax();
// We'll fallback on cscore's implementation for windows lifecam
this.minExposure = 0;
this.maxExposure = 100;
}

@Override
Expand All @@ -32,18 +29,8 @@ public void setExposureRaw(double exposureRaw) {

int propVal = (int) MathUtils.limit(exposureRaw, minExposure, maxExposure);

propVal = MathUtils.quantize(propVal, allowableExposures);

logger.debug(
"Setting property "
+ autoExposureProp.getName()
+ " to "
+ propVal
+ " (user requested "
+ exposureRaw
+ " μs)");

exposureAbsProp.set(propVal);
//exposureAbsProp.set(propVal);
camera.setExposureManual(propVal);

this.lastExposureRaw = exposureRaw;

Expand All @@ -64,15 +51,12 @@ public void setAutoExposure(boolean cameraAutoExposure) {
logger.debug("Setting auto exposure to " + cameraAutoExposure);

if (!cameraAutoExposure) {

// Most cameras leave exposure time absolute at the last value from their AE
// algorithm.
// Set it back to the exposure slider value
setExposureRaw(this.lastExposureRaw);

camera.setExposureManual( (int) this.lastExposureRaw);
} else {
softSet("WhiteBalance", 4000);
exposureAbsProp.set(0);
camera.setExposureAuto();
}
}

Expand Down

0 comments on commit 4a15f27

Please sign in to comment.