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) :
52 m_png_compression{png_compression},
53 m_pool_max_size{thread_pool_size > 0 ? thread_pool_size : 1}
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)
96 recordSnapshot(cv_image, path);
103 writeMetadataLine(
"png_compression",
"unsigned int",
std::to_string(m_png_compression));
104 m_pool_current_size.store(0);
110 std::unique_lock l{m_pool_mutex};
111 m_pool_cv.wait(l, [&] {
return m_pool_current_size.load() == 0; });
118 const cv::Mat& frame,
119 const std::chrono::microseconds timestamp)
121 std::scoped_lock l{m_record_frame_mutex};
122 const auto& [sequence_number, frame_name] = writeMetadataFrame(frame, timestamp);
123 const std::filesystem::path path = deriveFramePath(sequence_number, frame_name);
126 std::unique_lock l{m_pool_mutex};
127 m_pool_cv.wait(l, [&] {
return m_pool_current_size.load() < m_pool_max_size; });
131 std::thread([
this, path, frame_cp = frame.clone()] { recordFrameAsync(path, frame_cp); })
137 const std::filesystem::path path,
138 const cv::Mat& frame)
140 m_pool_current_size++;
142 std::vector<int> params{cv::IMWRITE_PNG_COMPRESSION,
143 static_cast<int>(m_png_compression),
144 cv::IMWRITE_PNG_STRATEGY,
145 cv::IMWRITE_PNG_STRATEGY_RLE};
146 cv::imwrite(path.string(), frame, params);
148 m_pool_current_size--;
149 m_pool_cv.notify_all();