mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Create VideoCamera base class and move camera settings functions to it.
This makes them available for both UsbCamera and HttpCamera / AxisCamera. To avoid virtual functions in the public-facing interface, move the implementation of the camera settings functions to the core library.
This commit is contained in:
@@ -242,6 +242,20 @@ CS_Sink* CS_EnumerateSourceSinks(CS_Source source, int* count,
|
||||
CS_Source CS_CopySource(CS_Source source, CS_Status* status);
|
||||
void CS_ReleaseSource(CS_Source source, CS_Status* status);
|
||||
|
||||
//
|
||||
// Camera Source Common Property Fuctions
|
||||
//
|
||||
void CS_SetCameraBrightness(CS_Source source, int brightness,
|
||||
CS_Status* status);
|
||||
int CS_GetCameraBrightness(CS_Source source, CS_Status* status);
|
||||
void CS_SetCameraWhiteBalanceAuto(CS_Source source, CS_Status* status);
|
||||
void CS_SetCameraWhiteBalanceHoldCurrent(CS_Source source, CS_Status* status);
|
||||
void CS_SetCameraWhiteBalanceManual(CS_Source source, int value,
|
||||
CS_Status* status);
|
||||
void CS_SetCameraExposureAuto(CS_Source source, CS_Status* status);
|
||||
void CS_SetCameraExposureHoldCurrent(CS_Source source, CS_Status* status);
|
||||
void CS_SetCameraExposureManual(CS_Source source, int value, CS_Status* status);
|
||||
|
||||
//
|
||||
// UsbCamera Source Functions
|
||||
//
|
||||
|
||||
@@ -203,6 +203,19 @@ llvm::ArrayRef<CS_Sink> EnumerateSourceSinks(
|
||||
CS_Source CopySource(CS_Source source, CS_Status* status);
|
||||
void ReleaseSource(CS_Source source, CS_Status* status);
|
||||
|
||||
//
|
||||
// Camera Source Common Property Fuctions
|
||||
//
|
||||
void SetCameraBrightness(CS_Source source, int brightness, CS_Status* status);
|
||||
int GetCameraBrightness(CS_Source source, CS_Status* status);
|
||||
void SetCameraWhiteBalanceAuto(CS_Source source, CS_Status* status);
|
||||
void SetCameraWhiteBalanceHoldCurrent(CS_Source source, CS_Status* status);
|
||||
void SetCameraWhiteBalanceManual(CS_Source source, int value,
|
||||
CS_Status* status);
|
||||
void SetCameraExposureAuto(CS_Source source, CS_Status* status);
|
||||
void SetCameraExposureHoldCurrent(CS_Source source, CS_Status* status);
|
||||
void SetCameraExposureManual(CS_Source source, int value, CS_Status* status);
|
||||
|
||||
//
|
||||
// UsbCamera Source Functions
|
||||
//
|
||||
|
||||
@@ -191,15 +191,8 @@ class VideoSource {
|
||||
CS_Source m_handle;
|
||||
};
|
||||
|
||||
/// 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";
|
||||
|
||||
/// A source that represents a video camera.
|
||||
class VideoCamera : public VideoSource {
|
||||
public:
|
||||
enum WhiteBalance {
|
||||
kFixedIndoor = 3000,
|
||||
@@ -209,24 +202,7 @@ class UsbCamera : public VideoSource {
|
||||
kFixedFlourescent2 = 5200
|
||||
};
|
||||
|
||||
UsbCamera() = default;
|
||||
|
||||
/// 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)
|
||||
UsbCamera(llvm::StringRef name, int dev);
|
||||
|
||||
/// Create a source for a USB camera based on device path.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param path Path to device (e.g. "/dev/video0" on Linux)
|
||||
UsbCamera(llvm::StringRef name, llvm::StringRef path);
|
||||
|
||||
/// Enumerate USB cameras on the local system.
|
||||
/// @return Vector of USB camera information (one for each camera)
|
||||
static std::vector<UsbCameraInfo> EnumerateUsbCameras();
|
||||
|
||||
/// Get the path to the device.
|
||||
std::string GetPath() const;
|
||||
VideoCamera() = default;
|
||||
|
||||
/// Set the brightness, as a percentage (0-100).
|
||||
void SetBrightness(int brightness);
|
||||
@@ -251,12 +227,38 @@ class UsbCamera : public VideoSource {
|
||||
|
||||
/// Set the exposure to manual, as a percentage (0-100).
|
||||
void SetExposureManual(int value);
|
||||
|
||||
protected:
|
||||
explicit VideoCamera(CS_Source handle) : VideoSource(handle) {}
|
||||
};
|
||||
|
||||
/// A source that represents a USB camera.
|
||||
class UsbCamera : public VideoCamera {
|
||||
public:
|
||||
UsbCamera() = default;
|
||||
|
||||
/// 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)
|
||||
UsbCamera(llvm::StringRef name, int dev);
|
||||
|
||||
/// Create a source for a USB camera based on device path.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param path Path to device (e.g. "/dev/video0" on Linux)
|
||||
UsbCamera(llvm::StringRef name, llvm::StringRef path);
|
||||
|
||||
/// Enumerate USB cameras on the local system.
|
||||
/// @return Vector of USB camera information (one for each camera)
|
||||
static std::vector<UsbCameraInfo> EnumerateUsbCameras();
|
||||
|
||||
/// Get the path to the device.
|
||||
std::string GetPath() const;
|
||||
};
|
||||
|
||||
/// A source that represents a MJPEG-over-HTTP (IP) camera.
|
||||
class HttpCamera : public VideoSource {
|
||||
class HttpCamera : public VideoCamera {
|
||||
public:
|
||||
enum CameraKind {
|
||||
enum HttpCameraKind {
|
||||
kUnknown = CS_HTTP_UNKNOWN,
|
||||
kMJPGStreamer = CS_HTTP_MJPGSTREAMER,
|
||||
kCSCore = CS_HTTP_CSCORE,
|
||||
@@ -268,27 +270,28 @@ class HttpCamera : public VideoSource {
|
||||
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
|
||||
/// @param kind Camera kind (e.g. kAxis)
|
||||
HttpCamera(llvm::StringRef name, llvm::StringRef url,
|
||||
CameraKind kind = kUnknown);
|
||||
HttpCameraKind kind = kUnknown);
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
|
||||
/// @param kind Camera kind (e.g. kAxis)
|
||||
HttpCamera(llvm::StringRef name, const char* url, CameraKind kind = kUnknown);
|
||||
HttpCamera(llvm::StringRef name, const char* url,
|
||||
HttpCameraKind kind = kUnknown);
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
|
||||
/// @param kind Camera kind (e.g. kAxis)
|
||||
HttpCamera(llvm::StringRef name, const std::string& url,
|
||||
CameraKind kind = kUnknown);
|
||||
HttpCameraKind kind = kUnknown);
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param urls Array of Camera URLs
|
||||
/// @param kind Camera kind (e.g. kAxis)
|
||||
HttpCamera(llvm::StringRef name, llvm::ArrayRef<std::string> urls,
|
||||
CameraKind kind = kUnknown);
|
||||
HttpCameraKind kind = kUnknown);
|
||||
|
||||
/// Create a source for a MJPEG-over-HTTP (IP) camera.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
@@ -296,12 +299,12 @@ class HttpCamera : public VideoSource {
|
||||
/// @param kind Camera kind (e.g. kAxis)
|
||||
template <typename T>
|
||||
HttpCamera(llvm::StringRef name, std::initializer_list<T> urls,
|
||||
CameraKind kind = kUnknown);
|
||||
HttpCameraKind kind = kUnknown);
|
||||
|
||||
/// Get the kind of HTTP camera.
|
||||
/// Autodetection can result in returning a different value than the camera
|
||||
/// was created with.
|
||||
CameraKind GetCameraKind() const;
|
||||
HttpCameraKind GetHttpCameraKind() const;
|
||||
|
||||
/// Change the URLs used to connect to the camera.
|
||||
void SetUrls(llvm::ArrayRef<std::string> urls);
|
||||
|
||||
@@ -160,6 +160,46 @@ inline std::vector<VideoMode> VideoSource::EnumerateVideoModes() const {
|
||||
return EnumerateSourceVideoModes(m_handle, &status);
|
||||
}
|
||||
|
||||
inline void VideoCamera::SetBrightness(int brightness) {
|
||||
m_status = 0;
|
||||
SetCameraBrightness(m_handle, brightness, &m_status);
|
||||
}
|
||||
|
||||
inline int VideoCamera::GetBrightness() {
|
||||
m_status = 0;
|
||||
return GetCameraBrightness(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoCamera::SetWhiteBalanceAuto() {
|
||||
m_status = 0;
|
||||
SetCameraWhiteBalanceAuto(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoCamera::SetWhiteBalanceHoldCurrent() {
|
||||
m_status = 0;
|
||||
SetCameraWhiteBalanceHoldCurrent(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoCamera::SetWhiteBalanceManual(int value) {
|
||||
m_status = 0;
|
||||
SetCameraWhiteBalanceManual(m_handle, value, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoCamera::SetExposureAuto() {
|
||||
m_status = 0;
|
||||
SetCameraExposureAuto(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoCamera::SetExposureHoldCurrent() {
|
||||
m_status = 0;
|
||||
SetCameraExposureHoldCurrent(m_handle, &m_status);
|
||||
}
|
||||
|
||||
inline void VideoCamera::SetExposureManual(int value) {
|
||||
m_status = 0;
|
||||
SetCameraExposureManual(m_handle, value, &m_status);
|
||||
}
|
||||
|
||||
inline UsbCamera::UsbCamera(llvm::StringRef name, int dev) {
|
||||
m_handle = CreateUsbCameraDev(name, dev, &m_status);
|
||||
}
|
||||
@@ -178,71 +218,27 @@ inline std::string UsbCamera::GetPath() const {
|
||||
return ::cs::GetUsbCameraPath(m_handle, &m_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,
|
||||
CameraKind kind) {
|
||||
HttpCameraKind kind) {
|
||||
m_handle = CreateHttpCamera(
|
||||
name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
|
||||
&m_status);
|
||||
}
|
||||
|
||||
inline HttpCamera::HttpCamera(llvm::StringRef name, const char* url,
|
||||
CameraKind kind) {
|
||||
HttpCameraKind kind) {
|
||||
m_handle = CreateHttpCamera(
|
||||
name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
|
||||
&m_status);
|
||||
}
|
||||
|
||||
inline HttpCamera::HttpCamera(llvm::StringRef name, const std::string& url,
|
||||
CameraKind kind)
|
||||
HttpCameraKind kind)
|
||||
: HttpCamera(name, llvm::StringRef{url}, kind) {}
|
||||
|
||||
inline HttpCamera::HttpCamera(llvm::StringRef name,
|
||||
llvm::ArrayRef<std::string> urls,
|
||||
CameraKind kind) {
|
||||
HttpCameraKind kind) {
|
||||
m_handle = CreateHttpCamera(
|
||||
name, urls, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
|
||||
&m_status);
|
||||
@@ -250,7 +246,8 @@ inline HttpCamera::HttpCamera(llvm::StringRef name,
|
||||
|
||||
template <typename T>
|
||||
inline HttpCamera::HttpCamera(llvm::StringRef name,
|
||||
std::initializer_list<T> urls, CameraKind kind) {
|
||||
std::initializer_list<T> urls,
|
||||
HttpCameraKind kind) {
|
||||
std::vector<std::string> vec;
|
||||
vec.reserve(urls.size());
|
||||
for (const auto& url : urls) vec.emplace_back(url);
|
||||
@@ -259,9 +256,9 @@ inline HttpCamera::HttpCamera(llvm::StringRef name,
|
||||
&m_status);
|
||||
}
|
||||
|
||||
inline HttpCamera::CameraKind HttpCamera::GetCameraKind() const {
|
||||
inline HttpCamera::HttpCameraKind HttpCamera::GetHttpCameraKind() const {
|
||||
m_status = 0;
|
||||
return static_cast<CameraKind>(
|
||||
return static_cast<HttpCameraKind>(
|
||||
static_cast<int>(::cs::GetHttpCameraKind(m_handle, &m_status)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user