VOXL OpenVINS Server 1.0
Visual Inertial Odometry Server for VOXL Platform
Loading...
Searching...
No Matches
CameraQueueFusion.h
Go to the documentation of this file.
1/**
2 * @file CameraQueueFusion.h
3 * @brief Camera queue fusion system for VOXL OpenVINS
4 * @author Zauberflote
5 * @date 2025
6 * @version 1.0
7 *
8 * This header defines the camera queue fusion system that synchronizes
9 * and combines data from multiple cameras. It provides temporal alignment
10 * and batch processing capabilities for multi-camera VIO systems.
11 */
12
13#ifndef CAMERA_QUEUE_FUSION_H
14#define CAMERA_QUEUE_FUSION_H
15
16// Standard includes
17#include <vector>
18#include <memory>
19#include <mutex>
20#include <atomic>
21#include <iostream>
22#include <condition_variable>
23#include <deque>
24#include <thread>
25
26// Third-party includes
27#include <opencv2/opencv.hpp>
28
29// Local includes
30#include "VoxlVars.h"
31#include "VoxlCommon.h"
32#include "CameraBase.h"
33#include "MonoCameraMinimal.h"
34
35// ============================================================================
36// CONSTANTS
37// ============================================================================
38
39/**
40 * @brief Maximum number of cameras supported
41 *
42 * Limited by 32-bit mask implementation for camera ready tracking
43 */
44constexpr size_t MAX_CAMERA_COUNT = 6;
45
46// ============================================================================
47// CAMERA QUEUE FUSION CLASS
48// ============================================================================
49
50/**
51 * @class CameraQueueFusion
52 * @brief Camera queue fusion system for multi-camera synchronization
53 *
54 * This class implements a sophisticated system for synchronizing and
55 * fusing data from multiple cameras. It uses a mask-based approach to
56 * track camera readiness and provides temporal alignment of camera data.
57 *
58 * Features:
59 * - Multi-camera synchronization using bit masks
60 * - Temporal alignment of camera frames
61 * - Thread-safe queue management
62 * - Event-driven processing with condition variables
63 * - Batch processing capabilities
64 *
65 * The system works by:
66 * 1. Tracking which cameras have new data available
67 * 2. Waiting for all expected cameras to be ready
68 * 3. Fusing the synchronized data into batches
69 * 4. Providing sorted output for VIO processing
70 */
72{
73public:
74 /**
75 * @brief Get singleton instance
76 * @return Reference to the singleton CameraQueueFusion instance
77 */
79
80 /**
81 * @brief Start the fusion system
82 *
83 * Initializes the fusion system with the specified number of cameras
84 * and starts the background fusion thread.
85 *
86 * @param num_cams Number of cameras to synchronize
87 */
88 void start(size_t num_cams);
89
90 /**
91 * @brief Mark a camera as ready with new data
92 *
93 * This method is called when a camera has new data available.
94 * It updates the camera ready mask and may trigger fusion processing.
95 *
96 * @param cam_id Camera identifier (0-based)
97 */
98 void markCameraReady(size_t cam_id);
99
100 /**
101 * @brief Get sorted batch of camera data
102 *
103 * Retrieves a batch of synchronized camera data that is sorted
104 * by timestamp and filtered by the specified cutoff time.
105 *
106 * @param timestamp_cutoff Timestamp cutoff for data inclusion
107 * @param out Output vector to store the sorted camera data
108 * @return true if data was retrieved, false if no data available
109 */
110 bool getSortedBatch(double timestamp_cutoff, std::vector<ov_core::CameraData> &out);
111
112private:
113 /**
114 * @brief Main fusion loop
115 *
116 * Background thread function that continuously processes camera data
117 * and performs temporal synchronization and fusion.
118 */
119 void fusionLoop();
120
121 // ============================================================================
122 // PRIVATE MEMBER VARIABLES
123 // ============================================================================
124
125 /** @brief Bit mask indicating which cameras are ready */
126 std::atomic<uint32_t> camera_ready_mask_{0};
127
128 /** @brief Expected mask when all cameras should be ready */
129 uint32_t expected_mask_ = 0;
130
131 /** @brief Number of cameras in the system */
132 size_t num_cams_ = 0;
133
134 /** @brief Mutex for condition variable synchronization */
135 std::mutex cv_mtx_;
136
137 /** @brief Condition variable for event-driven wake up */
138 std::condition_variable cv_;
139
140 /** @brief Mutex for fusion data access */
141 std::mutex fusion_mutex_;
142
143 /** @brief Queue of fused camera frames */
144 std::deque<ov_core::CameraData> fused_frames_;
145
146 /** @brief Flag indicating if fusion system is running */
147 std::atomic<bool> running_{false};
148
149 /** @brief Background fusion thread */
150 std::thread fusion_thread_;
151};
152
153#endif // CAMERA_QUEUE_FUSION_H
Base class for camera implementations in VOXL OpenVINS.
constexpr size_t MAX_CAMERA_COUNT
Maximum number of cameras supported.
Monocular camera implementation for VOXL OpenVINS.
Common definitions and utilities for the VOXL OpenVINS server.
Global variable declarations and constants for VOXL OpenVINS server.
Camera queue fusion system for multi-camera synchronization.
static CameraQueueFusion & getInstance()
Get singleton instance.
void start(size_t num_cams)
Start the fusion system.
void markCameraReady(size_t cam_id)
Mark a camera as ready with new data.
bool getSortedBatch(double timestamp_cutoff, std::vector< ov_core::CameraData > &out)
Get sorted batch of camera data.