IRSOL
C++ code implementing socket server for interacting with Baumer camera.
interface.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include "irsol/assert.hpp"
15#include "irsol/types.hpp"
16#include "irsol/utils.hpp"
17
18#include <chrono>
19#include <mutex>
20#include <neoapi/neoapi.hpp>
21#include <optional>
22#include <string>
23#include <type_traits>
24#include <unordered_map>
25#include <variant>
26
27namespace irsol {
28
47namespace camera {
48
61{
62public:
64 using image_t = NeoAPI::Image;
65
67 using camera_param_t = std::variant<bool, int, int64_t, double, std::string, const char*>;
68
70 static constexpr irsol::types::duration_t DEFAULT_EXPOSURE_TIME = std::chrono::milliseconds(2);
71
82 Interface(NeoAPI::Cam cam = irsol::utils::loadDefaultCamera());
83
85 Interface(Interface&& other);
86
89
95
103 static Interface HalfResolution();
104
112 std::string cameraInfoAsString() const;
113
122 std::string cameraStatusAsString() const;
123
128 NeoAPI::Cam& getNeoCam();
129
137 bool isConnected() const
138 {
139 return m_cam.IsConnected();
140 }
141
147 void resetSensorArea();
148
155
163
179 template<
180 typename T,
181 std::enable_if_t<
182 std::is_integral_v<T> || std::is_floating_point_v<T> || std::is_same_v<std::string, T>,
183 int> = 0>
184 T getParam(const std::string& param) const;
185
194 std::string getParam(const std::string& param) const;
195
212 template<
213 typename T,
214 std::enable_if_t<
215 std::is_integral_v<std::decay_t<T>> || std::is_floating_point_v<std::decay_t<T>> ||
216 std::is_same_v<std::decay_t<T>, std::string>,
217 int> = 0>
218 T setParam(const std::string& param, T value);
219
228 template<typename T, std::enable_if_t<std::is_same_v<std::decay_t<T>, const char*>, int> = 0>
229 std::string setParam(const std::string& param, T value);
230
240 void setMultiParam(const std::unordered_map<std::string, camera_param_t>& params);
241
247 void trigger(const std::string& param);
248
259 image_t captureImage(std::optional<irsol::types::duration_t> timeout = std::nullopt);
260
261private:
263 mutable std::mutex m_camMutex;
264
266 NeoAPI::Cam m_cam;
267
271
279 template<
280 typename T,
281 std::enable_if_t<
282 std::is_integral_v<std::decay_t<T>> || std::is_floating_point_v<std::decay_t<T>> ||
283 std::is_same_v<std::decay_t<T>, std::string> ||
284 std::is_same_v<std::decay_t<T>, const char*>,
285 int> = 0>
286 void setParamNonThreadSafe(const std::string& param, T value);
287};
288
289} // namespace camera
290} // namespace irsol
291
Assertion macros and utilities based on the PPK_ASSERT library.
High-level wrapper around the NeoAPI camera for synchronized access.
Definition interface.hpp:61
std::variant< bool, int, int64_t, double, std::string, const char * > camera_param_t
Union of all supported types for camera parameters.
Definition interface.hpp:67
std::string cameraStatusAsString() const
Get current camera status.
void setParamNonThreadSafe(const std::string &param, T value)
Internal, non-thread-safe parameter setter used by setParam.
image_t captureImage(std::optional< irsol::types::duration_t > timeout=std::nullopt)
Capture a single image from the camera.
std::string setParam(const std::string &param, T value)
Specialization for setting const char* values as strings.
std::mutex m_camMutex
Mutex to protect access to camera parameters and image acquisition.
void trigger(const std::string &param)
Trigger a camera feature (e.g., software trigger).
static Interface HalfResolution()
Factory method to create a camera interface using half sensor resolution.
Definition interface.cpp:63
T setParam(const std::string &param, T value)
Set a camera parameter of arbitrary type T.
T getParam(const std::string &param) const
Retrieve a camera parameter of arbitrary type T.
NeoAPI::Image image_t
Alias for the image type returned by the NeoAPI.
Definition interface.hpp:64
NeoAPI::Cam & getNeoCam()
Access the underlying NeoAPI camera instance.
std::string cameraInfoAsString() const
Get human-readable camera information.
Definition interface.cpp:79
irsol::types::duration_t setExposure(irsol::types::duration_t exposure)
Set the exposure time of the camera.
static constexpr irsol::types::duration_t DEFAULT_EXPOSURE_TIME
Default exposure time (2 milliseconds) used to initialize the camera.
Definition interface.hpp:70
bool isConnected() const
Check if the camera is currently connected.
Interface & operator=(Interface &&other)
Move assignment operator.
Definition interface.cpp:42
void resetSensorArea()
Reset the sensor area to the full sensor dimensions.
void setMultiParam(const std::unordered_map< std::string, camera_param_t > &params)
Set multiple parameters in one call.
static Interface FullResolution()
Factory method to create a camera interface using full sensor resolution.
Definition interface.cpp:49
NeoAPI::Cam m_cam
Internal camera instance from NeoAPI.
irsol::types::duration_t getExposure() const
Get the current exposure time from the camera.
irsol::types::duration_t m_CachedExposureTime
clock_t::duration duration_t
Alias for a duration of time as defined by clock_t.
Definition types.hpp:128
NeoAPI::Cam loadDefaultCamera()
Loads the default camera device.
Definition utils.cpp:196
auto value
Core type definitions for networking, time handling, and protocol values used throughout the irsol li...
General utility functions used throughout the irsol library.