33 #include <opencv2/opencv.hpp>
49 m_png_compression{png_compression},
50 m_pool_max_size{thread_pool_size > 0 ? thread_pool_size : 1}
66 std::filesystem::path snapshotPath(path);
69 ARMARX_CHECK_EXPRESSION(std::filesystem::exists(path.parent_path())) <<
"Cannot take snapshot, path '" + path.parent_path().string() +
"' does ot exist";
71 if (snapshotPath.extension() !=
".png")
73 snapshotPath +=
".png";
76 const int snapshot_compression = 9;
77 std::vector<int> params {cv::IMWRITE_PNG_COMPRESSION, snapshot_compression,
78 cv::IMWRITE_PNG_STRATEGY, cv::IMWRITE_PNG_STRATEGY_RLE};
79 cv::imwrite(snapshotPath.string(), image, params);
89 recordSnapshot(cv_image, path);
97 writeMetadataLine(
"png_compression",
"unsigned int",
std::to_string(m_png_compression));
98 m_pool_current_size.store(0);
105 std::unique_lock l{m_pool_mutex};
106 m_pool_cv.wait(l, [&] {
return m_pool_current_size.load() == 0; });
115 std::scoped_lock l{m_record_frame_mutex};
116 const auto& [sequence_number, frame_name] = writeMetadataFrame(frame, timestamp);
117 const std::filesystem::path path = deriveFramePath(sequence_number, frame_name);
120 std::unique_lock l{m_pool_mutex};
121 m_pool_cv.wait(l, [&] {
return m_pool_current_size.load() < m_pool_max_size; });
125 std::thread([
this, path, frame_cp = frame.clone()]
127 recordFrameAsync(path, frame_cp);
135 m_pool_current_size++;
137 std::vector<int> params {cv::IMWRITE_PNG_COMPRESSION,
static_cast<int>(m_png_compression),
138 cv::IMWRITE_PNG_STRATEGY, cv::IMWRITE_PNG_STRATEGY_RLE};
139 cv::imwrite(path.string(), frame, params);
141 m_pool_current_size--;
142 m_pool_cv.notify_all();