46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#ifndef COMPONENT__RECORDER_HPP
|
|
#define COMPONENT__RECORDER_HPP
|
|
|
|
#include <Eigen/Geometry>
|
|
#include <chrono>
|
|
#include <fstream>
|
|
#include <opencv2/opencv.hpp>
|
|
#include <thread>
|
|
|
|
#include "src/component/thread_safe_queue.hpp"
|
|
namespace component
|
|
{
|
|
class Recorder
|
|
{
|
|
public:
|
|
Recorder(double fps = 30);
|
|
~Recorder();
|
|
void record(
|
|
const cv::Mat & img, const Eigen::Quaterniond & q,
|
|
const std::chrono::steady_clock::time_point & timestamp);
|
|
|
|
private:
|
|
struct FrameData
|
|
{
|
|
cv::Mat img;
|
|
Eigen::Quaterniond q;
|
|
std::chrono::steady_clock::time_point timestamp;
|
|
};
|
|
bool init_;
|
|
std::atomic<bool> stop_thread_;
|
|
double fps_;
|
|
std::string text_path_;
|
|
std::string video_path_;
|
|
std::ofstream text_writer_;
|
|
cv::VideoWriter video_writer_;
|
|
std::chrono::steady_clock::time_point start_time_;
|
|
std::chrono::steady_clock::time_point last_time_;
|
|
component::ThreadSafeQueue<FrameData> queue_;
|
|
std::thread saving_thread_; // 负责保存帧数据的线程
|
|
void init(const cv::Mat & img);
|
|
void save_to_file();
|
|
};
|
|
|
|
} // namespace component
|
|
|
|
#endif // COMPONENT__RECORDER_HPP
|