Skip to content

Commit

Permalink
Fix Libcamera exposure bugs
Browse files Browse the repository at this point in the history
With ov9281 exposure 0 through 6 do not actually do anything. Gain of 0 would also enable auto exposure.
  • Loading branch information
BytingBulldogs3539 committed Dec 29, 2023
1 parent e0d8f5e commit 0db9bd8
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,21 @@ public void setExposure(double exposure) {
// Auto-exposure is active right now, don't set anything.
return;
}
MathUtils.map(exposure, 0.0, 100.0, 0.1, 100);

// HACKS!
// If we set exposure too low, libcamera crashes or slows down
// Very weird and smelly
// For now, band-aid this by just not setting it lower than the "it breaks" limit
// is different depending on camera.
// is different depending on camera.
if (sensorModel == LibCameraJNI.SensorModel.OV9281) {
if (exposure < 6.0) {
exposure = 6.0;
}
exposure = MathUtils.map(exposure, 0.1, 100.0, 6.0, 100);
} else if (sensorModel == LibCameraJNI.SensorModel.OV5647) {
if (exposure < 0.7) {
exposure = 0.7;
}
exposure = MathUtils.map(exposure, 0.1, 100.0, 0.7, 100);
}

lastManualExposure = exposure;
var success = LibCameraJNI.setExposure(r_ptr, (int) Math.round(exposure) * 800);
var success = LibCameraJNI.setExposure(r_ptr, (int) (exposure * 800));
if (!success) LibcameraGpuSource.logger.warn("Couldn't set Pi Camera exposure");
}

Expand All @@ -164,8 +161,7 @@ public void setBrightness(int brightness) {
@Override
public void setGain(int gain) {
lastGain = gain;
// TODO units here seem odd -- 5ish seems legit? So divide by 10
var success = LibCameraJNI.setAnalogGain(r_ptr, gain / 10.0);
var success = LibCameraJNI.setAnalogGain(r_ptr, MathUtils.map(gain, 0.0, 100.0, 1, 10));
if (!success) LibcameraGpuSource.logger.warn("Couldn't set Pi Camera gain");
}

Expand Down

0 comments on commit 0db9bd8

Please sign in to comment.