Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grayscale passthrough #1083

Merged
merged 18 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
BytingBulldogs3539 marked this conversation as resolved.
Show resolved Hide resolved
} else if (sensorModel == LibCameraJNI.SensorModel.OV5647) {
if (exposure < 0.7) {
exposure = 0.7;
}
exposure = MathUtils.map(exposure, 0.1, 100.0, 0.7, 100);
BytingBulldogs3539 marked this conversation as resolved.
Show resolved Hide resolved
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.opencv.core.Mat;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.raspi.LibCameraJNI;
import org.photonvision.raspi.LibCameraJNI.SensorModel;
import org.photonvision.vision.camera.LibcameraGpuSettables;
import org.photonvision.vision.frame.Frame;
import org.photonvision.vision.frame.FrameProvider;
Expand Down Expand Up @@ -91,9 +90,7 @@ public Frame get() {

@Override
public void requestFrameThresholdType(FrameThresholdType type) {
if (settables.getModel() == SensorModel.OV9281 && type.equals(FrameThresholdType.GREYSCALE))
LibCameraJNI.setGpuProcessType(settables.r_ptr, 4); // 4 = Grayscale pass through.
else LibCameraJNI.setGpuProcessType(settables.r_ptr, type.ordinal());
LibCameraJNI.setGpuProcessType(settables.r_ptr, type.ordinal());
}

@Override
Expand Down
Binary file not shown.
Loading