33#include <opencv2/opencv.hpp>
47 const std::filesystem::path& filePath,
48 const std::string& file_name,
49 unsigned int png_compression,
50 unsigned int thread_pool_size) :
67 const std::filesystem::path& path)
69 std::filesystem::path snapshotPath(path);
73 <<
"Cannot take snapshot, path '" + path.parent_path().string() +
"' does ot exist";
75 if (snapshotPath.extension() !=
".png")
77 snapshotPath +=
".png";
80 const int snapshot_compression = 9;
81 std::vector<int> params{cv::IMWRITE_PNG_COMPRESSION,
83 cv::IMWRITE_PNG_STRATEGY,
84 cv::IMWRITE_PNG_STRATEGY_RLE};
85 cv::imwrite(snapshotPath.string(), image, params);
90 const CByteImage& image,
91 const std::filesystem::path& path)
118 const cv::Mat& frame,
119 const std::chrono::microseconds
timestamp)
123 const std::filesystem::path path =
deriveFramePath(sequence_number, frame_name);
131 std::thread([
this, path, frame_cp = frame.clone()] { recordFrameAsync(path, frame_cp); })
137 const std::filesystem::path path,
138 const cv::Mat& frame)
142 std::vector<int> params{cv::IMWRITE_PNG_COMPRESSION,
144 cv::IMWRITE_PNG_STRATEGY,
145 cv::IMWRITE_PNG_STRATEGY_RLE};
146 cv::imwrite(path.string(), frame, params);
virtual void stopRecording()
Stops the recording.
virtual std::tuple< unsigned int, std::string > writeMetadataFrame(const CByteImage &frame, std::chrono::microseconds timestamp)
virtual void writeMetadataLine(const std::string &var_name, std::string_view var_type, std::string_view var_value)
void startRecording() override
Starts the recording manually if constructed empty.
AbstractSequencedRecordingStrategy()
Default constructor to manually start the recording.
std::filesystem::path deriveFramePath(const unsigned int sequence_number, const std::string &frame_name)
Returns the next sequenced full path and increments the sequence number.
unsigned int m_png_compression
void startRecording() override
Starts the recording manually if constructed empty.
std::mutex m_record_frame_mutex
unsigned int m_pool_max_size
std::atomic< unsigned int > m_pool_current_size
static void recordSnapshot(const cv::Mat &image, const std::filesystem::path &path)
~PNGParallelRecordingStrategy() override
void recordFrame(const cv::Mat &frame, std::chrono::microseconds timestamp) override
Adds the given frame to the recording.
void stopRecording() override
Stops the recording.
void recordFrameAsync(std::filesystem::path path, const cv::Mat &frame)
std::condition_variable m_pool_cv
PNGParallelRecordingStrategy()
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_LESS_EQUAL(lhs, rhs)
This macro evaluates whether lhs is less or equal (<=) rhs and if it turns out to be false it will th...
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
void convert(const CByteImage &in, cv::Mat &out)
Converts an IVT CByteImage to OpenCV's BGR Mat.