#pragma once #include #include #include #include namespace zed { enum class PcMode { FULL, HALF }; struct Config { int resolution = 1080; int fps = 15; sl::DEPTH_MODE depth_mode = sl::DEPTH_MODE::NEURAL; int depth_min_mm = 200; int depth_max_mm = 600; bool depth_fill = false; bool point_cloud = false; PcMode pc_mode = PcMode::FULL; int confidence_threshold = 60; int texture_confidence_threshold = 100; std::string flip = "ON"; int warmup_frames = 30; static Config from_env(); }; struct Calibration { float fx = 0, fy = 0, cx = 0, cy = 0; std::vector distortion; }; class Camera { public: explicit Camera(const Config& config); ~Camera(); // One attempt, returning whether it succeeded. The caller decides when to try // again, so a camera that is down never blocks the dora event loop. bool open(); void close(); // Close the handle and reset the device over USB, where the model allows it. void reset(); void warmup(); bool grab(); bool is_open() const; // True while the SDK is reconnecting the camera after a link hiccup. bool recovering() const; // True when the last grabbed frame carries no picture at all. A camera whose // link has dropped does not necessarily fail its grabs: it can keep reporting // success and hand back a uniform frame. bool image_is_blank(); Calibration calibration() const; int64_t device_timestamp_ns(); sl::Mat& image(); sl::Mat& depth(); sl::Mat& point_cloud(); private: Config config_; sl::Camera zed_; sl::InitParameters init_params_; sl::RuntimeParameters runtime_params_; sl::Mat image_mat_; sl::Mat depth_mat_; sl::Mat point_cloud_mat_; // Read off the device once it is open and kept afterwards: resetting a wedged // camera needs the serial and the model, and by then the handle is gone. unsigned int serial_number_ = 0; sl::MODEL model_ = sl::MODEL::LAST; bool recovering_ = false; }; } // namespace zed