25 #define METADATA_VERSION "2.0"
35 #include <opencv2/opencv.hpp>
38 #include <Image/ByteImage.h>
52 const std::filesystem::path& file_path) :
53 m_file_path{file_path}, m_recording{
false}
76 <<
"Instance has already been initialised for recording";
79 std::filesystem::create_directories(m_file_path.parent_path());
86 const std::chrono::microseconds time)
94 recordFrame(cv_frame, time);
99 const std::chrono::microseconds time)
105 CByteImage ivt_frame;
107 recordFrame(ivt_frame, time);
113 writeMetadataLine(
"frame_count",
"unsigned int",
std::to_string(m_sequence_number));
115 if (m_metadata_file.is_open())
117 m_metadata_file.close();
121 std::filesystem::path
127 std::filesystem::path
130 return m_file_path.parent_path();
133 std::filesystem::path
136 return m_file_path.stem();
139 std::filesystem::path
142 return m_file_path.extension();
145 std::filesystem::path
148 std::filesystem::path path = getPath();
149 std::filesystem::path
filename = getStem().string() +
"_metadata.csv";
150 return std::filesystem::canonical(path) /
filename;
153 std::tuple<unsigned int, std::string>
155 const CByteImage& frame,
156 const std::chrono::microseconds timestamp)
159 "frame_height",
"unsigned int",
std::to_string(
static_cast<unsigned int>(frame.height)));
161 "frame_width",
"unsigned int",
std::to_string(
static_cast<unsigned int>(frame.width)));
162 return writeMetadataFrameFileInfo(timestamp);
165 std::tuple<unsigned int, std::string>
167 const cv::Mat& frame,
168 const std::chrono::microseconds timestamp)
170 writeMetadataLine(
"frame_height",
173 writeMetadataLine(
"frame_width",
176 return writeMetadataFrameFileInfo(timestamp);
179 std::tuple<unsigned int, std::string>
180 visionx::imrec::AbstractRecordingStrategy::writeMetadataFrameFileInfo(
181 const std::chrono::microseconds timestamp)
183 const unsigned int sequence_number = m_sequence_number++;
186 if (m_reference_time.count() == 0)
188 m_reference_time = timestamp;
189 writeMetadataDatetime(
"frame_0_system_reference_time", timestamp);
193 const std::chrono::microseconds normalized_time = timestamp - m_reference_time;
197 writeMetadataLine(
"frame_" +
std::to_string(sequence_number),
"string", normalized_time_str);
199 return {sequence_number, normalized_time_str};
204 const std::string& var_name,
205 const std::chrono::microseconds timestamp)
207 writeMetadataLine(var_name +
"_us",
"long",
std::to_string(timestamp.count()));
213 const std::string_view var_type,
214 const std::string_view var_value)
216 if (not m_metadata_file.is_open())
218 m_metadata_file.open(getMetadataPath());
219 writeMetadataLine(
"name",
"type",
"value");
224 if (m_written_metadata_variables.insert(var_name).second ==
false)
229 m_metadata_file << var_name <<
"," << var_type <<
"," << var_value <<
"\n";
230 m_metadata_file.flush();