bool CamConfig::applyToCamera(CameraHandle& cam) if (!validate()) return false; cam.setControl(CID_EXPOSURE_ABSOLUTE, params_.exposure_us); cam.setControl(CID_GAIN, params_.gain); cam.setControl(CID_AUTO_EXPOSURE, params_.auto_exposure ? 1 : 0);
is_dirty_ = false; return true; 4.1 Profiles & Hot-Swapping Allows switching between "indoor", "outdoor", "lowlight" profiles at runtime without reinitializing the camera. 4.2 Constraint Dependency E.g., if auto_exposure = true , then exposure_us becomes read-only; setting it triggers a warning or is deferred until auto mode is off. 4.3 Atomic Transactions Uses a temporary SensorParams copy. Only if all register writes succeed does the main params_ get updated – prevents partial configurations. 5. Common Pitfalls & Debugging Tips | Issue | Typical Cause in camconfig.cpp | |-------|----------------------------------| | Camera fails to stream | Applying resolution/FPS combo not supported by sensor (validation missing). | | Exposure changes ignored | Register address/unit wrong (ms vs µs) or auto-exposure still enabled. | | Crash on exit | Static CamConfig singleton holding a destroyed camera handle reference. | | Config file not found | Relative path breaks when working directory changes – use absolute path or findResourceFile() . | 6. Usage Example (Client Code) #include "camconfig.h" int main() try CamConfig cfg("/etc/camera/default.yaml"); cfg.load(); cfg.setExposure(1500.0); // 1.5 ms override cfg.applyToCamera(my_camera); catch (const std::exception& e) std::cerr << "CamConfig error: " << e.what() << std::endl; return EXIT_FAILURE; camconfig cpp
1. Overview camconfig.cpp is a critical module in embedded vision systems, robotics SDKs (e.g., ROS nodes for USB/GigE cameras), or automotive ADAS pipelines. Its primary responsibility is to parse, validate, store, and apply configuration parameters for one or more camera sensors. bool CamConfig::applyToCamera(CameraHandle& cam) if (
Unlike a simple header with hardcoded values, this implementation bridges static default settings (YAML/JSON/INI files) with dynamic runtime adjustments (exposure, gain, white balance). // Simplified from camconfig.hpp class CamConfig public: struct SensorParams int width, height, fps; double exposure_us; uint16_t gain; bool auto_exposure; ; CamConfig(const std::string& config_path); bool load(); // Parse file bool validate(); // Range/constraint checks bool applyToCamera(CameraHandle& cam); // Write to registers void saveToFile(const std::string& path); Common Pitfalls & Debugging Tips | Issue |
// Resolution change requires stream restart if (cam.isStreaming()) cam.stopStream(); cam.setResolution(params_.width, params_.height); if (cam.isStreaming()) cam.startStream();
bool CamConfig::validate() The applyToCamera() function serializes parameters into the camera’s register map (e.g., via I²C, UVC controls, or GenICam). A snippet from a real USB camera backend:
return EXIT_SUCCESS;