65 if (!is_system_ready())
69 if (
is_resetting.load(std::memory_order_relaxed))
return;
80 current_height = meta.height;
81 current_width = meta.width;
84 if (type == voxl::ImageType::CV_MAT)
86 if (meta.format == IMAGE_FORMAT_STEREO_RAW8)
88 process_raw8(meta, (
char*)frame);
93 fprintf(stderr,
"Unsupported image format: %d\n", meta.format);
97 if (type == voxl::ImageType::CL_MEM)
99 fprintf(stderr,
"Using CL_MEM is currently unsupported for stereo images\n");
106 std::lock_guard<std::mutex> lk(
reset_mtx);
129 void StereoCamera::process_raw8(
const camera_image_metadata_t &meta,
char *frame)
137 const int full_w = meta.width;
138 const int full_h = meta.height;
139 const size_t bytes_per_row = full_w;
140 const size_t bytes_one_img = bytes_per_row * full_h;
149 const bool dimensions_changed = (
use_mask_.rows != current_height ||
use_mask_.cols != current_width);
150 if (dimensions_changed) {
151 mask_dimensions_changed_ =
true;
165 update_masks_if_needed(should_mask_left, should_mask_right);
167 ov_core::CameraData message;
168 message.timestamp = (meta.timestamp_ns) * 1e-09;
170 message.sensor_ids.push_back(
get_id() + 0);
171 message.images.emplace_back(imgL.clone());
174 message.sensor_ids.push_back(
get_id() + 1);
175 message.images.emplace_back(imgR.clone());
176 message.masks.emplace_back(use_mask2_);
183 std::cerr <<
"Camera queue full — dropping frame from cam " <<
get_channel() << std::endl;
194 void StereoCamera::update_masks_if_needed(
bool should_mask_left,
bool should_mask_right)
197 const bool needs_update_left = !current_mask_state_left_.has_value() ||
198 current_mask_state_left_.value() != should_mask_left ||
199 mask_dimensions_changed_;
201 const bool needs_update_right = !current_mask_state_right_.has_value() ||
202 current_mask_state_right_.value() != should_mask_right ||
203 mask_dimensions_changed_;
205 if (!needs_update_left && !needs_update_right) {
210 current_mask_state_left_ = should_mask_left;
211 current_mask_state_right_ = should_mask_right;
212 mask_dimensions_changed_ =
false;
215 if (should_mask_left) {
217 use_mask_ = cv::Mat(current_height, current_width, CV_8UC1, cv::Scalar(255));
220 use_mask_ = cv::Mat(current_height, current_width, CV_8UC1, cv::Scalar(0));
223 if (should_mask_right) {
225 use_mask2_ = cv::Mat(current_height, current_width, CV_8UC1, cv::Scalar(255));
228 use_mask2_ = cv::Mat(current_height, current_width, CV_8UC1, cv::Scalar(0));
240 bool StereoCamera::is_system_resetting()
const
254 bool StereoCamera::is_system_ready()
const
Stereo camera implementation for VOXL OpenVINS.
bool occlude_stereo_right
Occlude stereo right.
volatile int64_t last_cam_time
Timestamp of last camera data (nanoseconds)
volatile int main_running
Main process running flag.
std::atomic< uint32_t > active_callbacks
Number of callbacks inside the system.
bool occlude_stereo_left
Occlude stereo left.
std::mutex reset_mtx
Mutex used by reset thread.
float takeoff_alt_threshold
Takeoff altitude threshold.
std::condition_variable reset_cv
Reset conditional variable.
std::atomic< bool > is_resetting
VIO reset state flag.
std::atomic< float > alt_z
Altitude z.
std::atomic< uint32_t > vio_error_codes
VIO error codes.
std::atomic< bool > is_imu_connected
IMU connection state.
std::atomic< bool > is_cam_connected
Camera connection state.
static CameraQueueFusion & getInstance()
Get singleton instance.
void markCameraReady(size_t cam_id)
Mark a camera as ready with new data.
Base class for all camera implementations.
cv::Mat use_mask_
Per-instance reusable mask for feature tracking.
int get_channel() const
Get the camera pipe channel.
size_t get_id() const
Get the camera identifier.
img_ringbuf_packet curr_message_
Instance-local buffer for image processing.
boost::lockfree::spsc_queue< ov_core::CameraData, boost::lockfree::capacity< 64 > > camera_queue
Lock-free SPSC queue for camera data.
StereoCamera(const cam_info &camera_info)
Constructor.
void process_image(const camera_image_metadata_t &meta, voxl::ImageType type, void *frame) override
Process incoming image data.
Main namespace for VOXL OpenVINS server components.
Camera information and calibration data.
uint8_t image_pixels[MAX_IMAGE_SIZE]
Raw image pixel data.
camera_image_metadata_t metadata
Image metadata (timestamp, format, etc.)
int camid
Camera identifier.