Skip to content

Commit 1176bd3

Browse files
committed
Add saturation slider
Resolves PhotonVision#2311 Signed-off-by: Jade Turner <spacey-sooty@proton.me>
1 parent afb73b3 commit 1176bd3

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

photon-client/src/components/dashboard/tabs/InputTab.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ const interactiveCols = computed(() =>
158158
(args) => useCameraSettingsStore().changeCurrentPipelineSetting({ cameraWhiteBalanceTemp: args }, false)
159159
"
160160
/>
161+
<pv-slider
162+
v-model="useCameraSettingsStore().currentPipelineSettings.cameraSaturation"
163+
label="Saturation Temperature"
164+
:min="useCameraSettingsStore().minSaturation"
165+
:max="useCameraSettingsStore().maxSaturation"
166+
:slider-cols="interactiveCols"
167+
@update:modelValue="
168+
(args) => useCameraSettingsStore().changeCurrentPipelineSetting({ cameraSaturation: args }, false)
169+
"
170+
/>
161171
<pv-switch
162172
v-model="useCameraSettingsStore().currentPipelineSettings.blockForFrames"
163173
:disabled="!useCameraSettingsStore().currentCameraSettings.matchedCameraInfo.PVUsbCameraInfo"

photon-client/src/stores/settings/CameraSettingsStore.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export const useCameraSettingsStore = defineStore("cameraSettings", {
8585
maxExposureRaw(): number {
8686
return this.currentCameraSettings.maxExposureRaw;
8787
},
88+
minSaturation(): number {
89+
return this.currentCameraSettings.minSaturation;
90+
},
91+
maxSaturation(): number {
92+
return this.currentCameraSettings.maxSaturation;
93+
},
8894
minWhiteBalanceTemp(): number {
8995
return this.currentCameraSettings.minWhiteBalanceTemp;
9096
},
@@ -137,6 +143,8 @@ export const useCameraSettingsStore = defineStore("cameraSettings", {
137143
isCSICamera: d.isCSICamera,
138144
minExposureRaw: d.minExposureRaw,
139145
maxExposureRaw: d.maxExposureRaw,
146+
minSaturation: d.minSaturation,
147+
maxSaturation: d.maxSaturation,
140148
pipelineNicknames: d.pipelineNicknames,
141149
currentPipelineIndex: d.currentPipelineIndex,
142150
pipelineSettings: d.currentPipelineSettings,

photon-core/src/main/java/org/photonvision/vision/camera/FileVisionSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public static class FileSourceSettables extends VisionSourceSettables {
118118
@Override
119119
public void setExposureRaw(double exposureRaw) {}
120120

121+
@Override
122+
public void setSaturation(double saturation) {}
123+
121124
public void setAutoExposure(boolean cameraAutoExposure) {}
122125

123126
@Override

photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ public class GenericUSBCameraSettables extends VisionSourceSettables {
4747
protected VideoProperty autoExposureProp = null;
4848
protected VideoProperty wbTempProp = null;
4949

50+
protected VideoProperty saturationProp = null;
51+
5052
protected double minExposure = 1;
5153
protected double maxExposure = 80000;
5254

55+
protected double minSaturation = 1;
56+
protected double maxSaturation = 80000; // TODO is this sane?
57+
5358
protected double minWhiteBalanceTemp = 1;
5459
protected double maxWhiteBalanceTemp = 4000;
5560
protected int lastWhiteBalanceTemp = 4000;
@@ -107,6 +112,19 @@ protected void setUpExposureProperties() {
107112
}
108113
}
109114

115+
protected void setUpSaturationProperty() {
116+
var satProp = findProperty("V4L2_CID_SATURATION", "saturation");
117+
118+
if (satProp.isEmpty()) {
119+
logger.warn("Could not find saturation property");
120+
return;
121+
} else {
122+
saturationProp = satProp.get();
123+
this.minSaturation = saturationProp.getMin();
124+
this.maxSaturation = saturationProp.getMax();
125+
}
126+
}
127+
110128
public void setAllCamDefaults() {
111129
// Common settings for all cameras to attempt to get their image
112130
// as close as possible to what we want for image processing
@@ -201,6 +219,28 @@ public double getMaxExposureRaw() {
201219
return maxExposure;
202220
}
203221

222+
@Override
223+
public void setSaturation(double saturation) {
224+
if (saturation >= 0.0) {
225+
try {
226+
int propVal = (int) MathUtil.clamp(saturation, minSaturation, maxSaturation);
227+
228+
logger.debug(
229+
"Setting property "
230+
+ saturationProp.getName()
231+
+ " to "
232+
+ propVal
233+
+ " (user requested "
234+
+ saturation
235+
+ ")");
236+
237+
saturationProp.set(propVal);
238+
} catch (VideoException e) {
239+
logger.error("Failed to set camera saturation!", e);
240+
}
241+
}
242+
}
243+
204244
@Override
205245
public void setExposureRaw(double exposureRaw) {
206246
if (exposureRaw >= 0.0) {
@@ -386,6 +426,7 @@ public void onCameraConnected() {
386426
// modes
387427
setUpExposureProperties();
388428
setUpWhiteBalanceProperties();
429+
setUpSaturationProperty();
389430
cacheVideoModes();
390431

391432
setAllCamDefaults();

photon-core/src/main/java/org/photonvision/vision/camera/csi/LibcameraGpuSettables.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ public void setAutoExposure(boolean cameraAutoExposure) {
131131
}
132132
}
133133

134+
@Override
135+
public void setSaturation(double saturation) {
136+
// TODO need to implement this on JNI side as well
137+
}
138+
134139
@Override
135140
public void setExposureRaw(double exposureRaw) {
136141
logger.debug("Setting exposure to " + exposureRaw);

photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceSettables.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public void onCameraConnected() {
5454
cameraPropertiesCached = true;
5555
}
5656

57+
public abstract void setSaturation(double saturation);
58+
5759
public abstract void setExposureRaw(double exposureRaw);
5860

5961
public abstract double getMinExposureRaw();

0 commit comments

Comments
 (0)