mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add USBCamera setting functions similar to the old WPILib nivision ones.
This commit is contained in:
@@ -9,6 +9,27 @@ package edu.wpi.cscore;
|
||||
|
||||
/// A source that represents a USB camera.
|
||||
public class USBCamera extends VideoSource {
|
||||
private static final String kPropWbAuto = "white_balance_temperature_auto";
|
||||
private static final String kPropWbValue = "white_balance_temperature";
|
||||
private static final String kPropExAuto = "exposure_auto";
|
||||
private static final String kPropExValue = "exposure_absolute";
|
||||
private static final String kPropBrValue = "brightness";
|
||||
|
||||
public class WhiteBalance {
|
||||
public static final int kFixedIndoor = 3000;
|
||||
public static final int kFixedOutdoor1 = 4000;
|
||||
public static final int kFixedOutdoor2 = 5000;
|
||||
public static final int kFixedFluorescent1 = 5100;
|
||||
public static final int kFixedFlourescent2 = 5200;
|
||||
}
|
||||
|
||||
// Cached to avoid duplicate string lookups
|
||||
private VideoProperty m_wbAuto;
|
||||
private VideoProperty m_wbValue;
|
||||
private VideoProperty m_exAuto;
|
||||
private VideoProperty m_exValue;
|
||||
private VideoProperty m_brValue;
|
||||
|
||||
/// Create a source for a USB camera based on device number.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param dev Device number (e.g. 0 for /dev/video0)
|
||||
@@ -28,4 +49,66 @@ public class USBCamera extends VideoSource {
|
||||
public static USBCameraInfo[] enumerateUSBCameras() {
|
||||
return CameraServerJNI.enumerateUSBCameras();
|
||||
}
|
||||
|
||||
/// Set the brightness, as a percentage (0-100).
|
||||
public synchronized void setBrightness(int brightness) {
|
||||
if (brightness > 100) {
|
||||
brightness = 100;
|
||||
} else if (brightness < 0) {
|
||||
brightness = 0;
|
||||
}
|
||||
if (m_brValue == null) m_brValue = getProperty(kPropBrValue);
|
||||
m_brValue.set(brightness);
|
||||
}
|
||||
|
||||
/// Get the brightness, as a percentage (0-100).
|
||||
public synchronized int getBrightness() {
|
||||
if (m_brValue == null) m_brValue = getProperty(kPropBrValue);
|
||||
return m_brValue.get();
|
||||
}
|
||||
|
||||
/// Set the white balance to auto.
|
||||
public synchronized void setWhiteBalanceAuto() {
|
||||
if (m_wbAuto == null) m_wbAuto = getProperty(kPropWbAuto);
|
||||
m_wbAuto.set(1); // auto
|
||||
}
|
||||
|
||||
/// Set the white balance to hold current.
|
||||
public synchronized void setWhiteBalanceHoldCurrent() {
|
||||
if (m_wbAuto == null) m_wbAuto = getProperty(kPropWbAuto);
|
||||
m_wbAuto.set(0); // manual
|
||||
}
|
||||
|
||||
/// Set the white balance to manual, with specified color temperature.
|
||||
public synchronized void setWhiteBalanceManual(int value) {
|
||||
if (m_wbAuto == null) m_wbAuto = getProperty(kPropWbAuto);
|
||||
m_wbAuto.set(0); // manual
|
||||
if (m_wbValue == null) m_wbValue = getProperty(kPropWbValue);
|
||||
m_wbValue.set(value);
|
||||
}
|
||||
|
||||
/// Set the exposure to auto aperature.
|
||||
public synchronized void setExposureAuto() {
|
||||
if (m_exAuto == null) m_exAuto = getProperty(kPropExAuto);
|
||||
m_exAuto.set(0); // auto; yes, this is opposite of white balance.
|
||||
}
|
||||
|
||||
/// Set the exposure to hold current.
|
||||
public synchronized void setExposureHoldCurrent() {
|
||||
if (m_exAuto == null) m_exAuto = getProperty(kPropExAuto);
|
||||
m_exAuto.set(1); // manual
|
||||
}
|
||||
|
||||
/// Set the exposure to manual, as a percentage (0-100).
|
||||
public synchronized void setExposureManual(int value) {
|
||||
if (m_exAuto == null) m_exAuto = getProperty(kPropExAuto);
|
||||
m_exAuto.set(1); // manual
|
||||
if (value > 100) {
|
||||
value = 100;
|
||||
} else if (value < 0) {
|
||||
value = 0;
|
||||
}
|
||||
if (m_exValue == null) m_exValue = getProperty(kPropExValue);
|
||||
m_exValue.set(value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user