Add USBCamera setting functions similar to the old WPILib nivision ones.

This commit is contained in:
Peter Johnson
2016-11-16 20:55:30 -08:00
parent 791cabbc26
commit dcf773c3ef
3 changed files with 166 additions and 0 deletions

View File

@@ -191,7 +191,22 @@ class VideoSource {
/// A source that represents a USB camera.
class USBCamera : public VideoSource {
private:
static constexpr char const* kPropWbAuto = "white_balance_temperature_auto";
static constexpr char const* kPropWbValue = "white_balance_temperature";
static constexpr char const* kPropExAuto = "exposure_auto";
static constexpr char const* kPropExValue = "exposure_absolute";
static constexpr char const* kPropBrValue = "brightness";
public:
enum WhiteBalance {
kFixedIndoor = 3000,
kFixedOutdoor1 = 4000,
kFixedOutdoor2 = 5000,
kFixedFluorescent1 = 5100,
kFixedFlourescent2 = 5200
};
/// 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)
@@ -205,6 +220,30 @@ class USBCamera : public VideoSource {
/// Enumerate USB cameras on the local system.
/// @return Vector of USB camera information (one for each camera)
static std::vector<USBCameraInfo> EnumerateUSBCameras();
/// Set the brightness, as a percentage (0-100).
void SetBrightness(int brightness);
/// Get the brightness, as a percentage (0-100).
int GetBrightness();
/// Set the white balance to auto.
void SetWhiteBalanceAuto();
/// Set the white balance to hold current.
void SetWhiteBalanceHoldCurrent();
/// Set the white balance to manual, with specified color temperature.
void SetWhiteBalanceManual(int value);
/// Set the exposure to auto aperature.
void SetExposureAuto();
/// Set the exposure to hold current.
void SetExposureHoldCurrent();
/// Set the exposure to manual, as a percentage (0-100).
void SetExposureManual(int value);
};
/// A source that represents a MJPEG-over-HTTP (IP) camera.

View File

@@ -173,6 +173,50 @@ inline std::vector<USBCameraInfo> USBCamera::EnumerateUSBCameras() {
return ::cs::EnumerateUSBCameras(&status);
}
inline void USBCamera::SetBrightness(int brightness) {
if (brightness > 100) {
brightness = 100;
} else if (brightness < 0) {
brightness = 0;
}
GetProperty(kPropBrValue).Set(brightness);
}
inline int USBCamera::GetBrightness() {
return GetProperty(kPropBrValue).Get();
}
inline void USBCamera::SetWhiteBalanceAuto() {
GetProperty(kPropWbAuto).Set(1); // auto
}
inline void USBCamera::SetWhiteBalanceHoldCurrent() {
GetProperty(kPropWbAuto).Set(0); // manual
}
inline void USBCamera::SetWhiteBalanceManual(int value) {
GetProperty(kPropWbAuto).Set(0); // manual
GetProperty(kPropWbValue).Set(value);
}
inline void USBCamera::SetExposureAuto() {
GetProperty(kPropExAuto).Set(0); // auto; yes, this is opposite of WB
}
inline void USBCamera::SetExposureHoldCurrent() {
GetProperty(kPropExAuto).Set(1); // manual
}
inline void USBCamera::SetExposureManual(int value) {
GetProperty(kPropExAuto).Set(1); // manual
if (value > 100) {
value = 100;
} else if (value < 0) {
value = 0;
}
GetProperty(kPropExValue).Set(value);
}
inline HTTPCamera::HTTPCamera(llvm::StringRef name, llvm::StringRef url) {
m_handle = CreateHTTPCamera(name, url, &m_status);
}

View File

@@ -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);
}
}