Add single-arm EtherCAT deployment configuration for device 234 using igc on enp1s0. Preserve configuration backup files outside the commit.
161 lines
5.2 KiB
C++
161 lines
5.2 KiB
C++
#ifndef CMVR_ES_ABSTRACT_CAMERA_H
|
|
#define CMVR_ES_ABSTRACT_CAMERA_H
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <chrono>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <opencv2/opencv.hpp>
|
|
#include <mutex>
|
|
#include "../abstract_device.h"
|
|
#include <Eigen/Core>
|
|
#include "cmvr/config/camera_config/camera_config.pb.h"
|
|
#include "devices/camera/common/include/camera_stream_overlay.h"
|
|
|
|
namespace cmvr::device {
|
|
enum CameraMode {PHOTO_MODE, VIDEO_MODE};
|
|
|
|
struct Rs2Intrinsics
|
|
{
|
|
float cx{0.0F};
|
|
float cy{0.0F};
|
|
float fx{0.0F};
|
|
float fy{0.0F};
|
|
float coeffs[5]{};
|
|
|
|
};
|
|
struct StreamFrameData
|
|
{
|
|
//原始图像数据
|
|
cv::Mat rgbImage;
|
|
//深度图原始数据
|
|
cv::Mat depthImage;
|
|
//彩色图像帧
|
|
std::vector<uint8_t> rgbFrame;
|
|
//深度图像帧
|
|
std::vector<uint8_t> depthFrame;
|
|
//编码格式
|
|
std::string codec = ".h264";
|
|
Rs2Intrinsics intrinsics{};
|
|
int width = 0;
|
|
int height = 0;
|
|
// Depth frames may use a different resolution from the encoded color frame.
|
|
int depth_width = 0;
|
|
int depth_height = 0;
|
|
int fps = 0;
|
|
bool bKey = false;
|
|
bool depthKey = false;
|
|
|
|
// Protocol-neutral real-time metadata. The producer fills these values
|
|
// when a complete encoded access unit is published.
|
|
uint64_t stream_epoch = 0;
|
|
uint64_t sequence = 0;
|
|
// Opaque producer-native timing/counter values. Their units and epoch
|
|
// are source-defined; zero means that the source did not provide them.
|
|
uint64_t source_timestamp = 0;
|
|
uint64_t source_frame_number = 0;
|
|
int64_t capture_monotonic_ns = 0;
|
|
int64_t capture_utc_ns = 0;
|
|
int64_t pts = 0;
|
|
int64_t dts = 0;
|
|
int32_t time_base_num = 1;
|
|
int32_t time_base_den = 1;
|
|
int64_t duration = 0;
|
|
bool discontinuity = false;
|
|
uint32_t codec_config_generation = 0;
|
|
std::vector<uint8_t> codec_config;
|
|
};
|
|
|
|
enum class PtzCommand {
|
|
TiltUp,
|
|
TiltDown,
|
|
PanLeft,
|
|
PanRight,
|
|
UpLeft,
|
|
UpRight,
|
|
DownLeft,
|
|
DownRight,
|
|
ZoomIn,
|
|
ZoomOut,
|
|
PanAuto
|
|
};
|
|
|
|
class AbstractCamera : public AbstractDevice {
|
|
public:
|
|
// 录制状态
|
|
enum class RecordingState {
|
|
STOPPED,
|
|
RECORDING,
|
|
PAUSED
|
|
};
|
|
public:
|
|
AbstractCamera() = default;
|
|
~AbstractCamera() override = default;
|
|
|
|
DeviceKind kind() const noexcept override { return DeviceKind::Camera; }
|
|
// Every implementation must take the same lock used by its state_
|
|
// writers; CameraState contains std::string and cannot be snapshotted
|
|
// safely while another thread mutates it.
|
|
virtual void getState(CameraState &state) = 0;
|
|
virtual void getRGBImage(cv::Mat &color, Rs2Intrinsics& intrinsics) {}
|
|
virtual bool supportsDepthImage() const { return false; }
|
|
virtual bool supportsDepthStream() const { return false; }
|
|
virtual void getDepthImage(cv::Mat &depth, Rs2Intrinsics& intrinsics) {}
|
|
virtual void getRGBDImages(cv::Mat &color, cv::Mat &depth, Rs2Intrinsics& intrinsics) {}
|
|
virtual void startRecording(const std::string &video_path) {}
|
|
virtual void stopRecording() {}
|
|
virtual void pauseRecording() {}
|
|
virtual void resumeRecording() {}
|
|
virtual void getEncodedFrame(StreamFrameData& frame_data, size_t& index) {}
|
|
virtual bool waitEncodedFrame(
|
|
StreamFrameData& frame_data,
|
|
size_t& index,
|
|
std::chrono::milliseconds timeout) {
|
|
(void)timeout;
|
|
getEncodedFrame(frame_data, index);
|
|
return !frame_data.rgbFrame.empty() || !frame_data.depthFrame.empty();
|
|
}
|
|
virtual bool getLatestEncodedFrame(StreamFrameData& frame_data, size_t& next_index) {
|
|
return false;
|
|
}
|
|
|
|
// Video overlay is a presentation-only snapshot. It is deliberately
|
|
// kept on the camera so the encoding thread can consume it without
|
|
// coupling the camera to AprilTag or task code.
|
|
void setStreamOverlay(const CameraStreamOverlay& overlay) {
|
|
std::lock_guard<std::mutex> lock(stream_overlay_mutex_);
|
|
stream_overlay_ = overlay;
|
|
}
|
|
|
|
CameraStreamOverlay streamOverlay() const {
|
|
std::lock_guard<std::mutex> lock(stream_overlay_mutex_);
|
|
return stream_overlay_;
|
|
}
|
|
|
|
virtual bool startStreaming() {return true;}
|
|
virtual void stopStreaming() {}
|
|
virtual bool controlPtz(PtzCommand command, bool stop, int speed) {
|
|
(void)command;
|
|
(void)stop;
|
|
(void)speed;
|
|
return false;
|
|
}
|
|
virtual bool requestKeyFrame() { return false; }
|
|
virtual Eigen::Vector3f get3DPointFromPixel(int u, int v) {return {0,0,0};}
|
|
protected:
|
|
CameraState state_{};
|
|
mutable std::mutex stream_overlay_mutex_;
|
|
CameraStreamOverlay stream_overlay_{};
|
|
void clear_error_() {
|
|
this->state_.is_error = false;
|
|
this->state_.error_message.clear();
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif // CMVR_ES_ABSTRACT_CAMERA_H
|