25#define METADATA_VERSION "2.0"
35#include <opencv2/opencv.hpp>
38#include <Image/ByteImage.h>
52 const std::filesystem::path& file_path) :
76 <<
"Instance has already been initialised for recording";
79 std::filesystem::create_directories(
m_file_path.parent_path());
86 const std::chrono::microseconds time)
99 const std::chrono::microseconds time)
105 CByteImage ivt_frame;
113 writeMetadataLine(
"frame_count",
"unsigned int", std::to_string(m_sequence_number));
115 if (m_metadata_file.is_open())
117 m_metadata_file.close();
148 std::filesystem::path path =
getPath();
149 std::filesystem::path filename =
getStem().string() +
"_metadata.csv";
150 return std::filesystem::canonical(path) / filename;
153std::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);
165std::tuple<unsigned int, std::string>
167 const cv::Mat& frame,
168 const std::chrono::microseconds
timestamp)
172 std::to_string(
static_cast<unsigned int>(frame.size().height)));
175 std::to_string(
static_cast<unsigned int>(frame.size().width)));
176 return writeMetadataFrameFileInfo(
timestamp);
179std::tuple<unsigned int, std::string>
180visionx::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)
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)
213 const std::string_view var_type,
214 const std::string_view var_value)
216 if (not m_metadata_file.is_open())
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();
virtual std::filesystem::path getDotExtension() const
Gets the extension plus preceeded dot of the configured file (e.g.
virtual void writeMetadataDatetime(const std::string &var_name, std::chrono::microseconds timestamp)
virtual std::filesystem::path getPath() const
Gets the path to the recording without filename.
virtual void stopRecording()
Stops the recording.
virtual ~AbstractRecordingStrategy()
Destructor.
virtual std::filesystem::path getMetadataPath() const
virtual bool isRecording() const
Indicates whether this instance is already initialised for recording.
AbstractRecordingStrategy()
Default constructor to start the recording manually.
virtual std::filesystem::path getStem() const
Gets the stem of the configured file (filename without extension)
std::filesystem::path m_file_path
Path to where the recording file should be written to.
virtual void startRecording()
Starts the recording manually if constructed empty.
virtual std::tuple< unsigned int, std::string > writeMetadataFrame(const CByteImage &frame, std::chrono::microseconds timestamp)
virtual void recordFrame(const CByteImage &frame, std::chrono::microseconds timestamp)
Adds the given frame to the recording.
virtual void writeMetadataLine(const std::string &var_name, std::string_view var_type, std::string_view var_value)
virtual std::filesystem::path getFilePath() const
Gets the raw file path for the recording as configured.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
std::string timestamp_to_string(std::chrono::microseconds ts)
std::string datetime_to_string(std::chrono::microseconds ts)
void convert(const CByteImage &in, cv::Mat &out)
Converts an IVT CByteImage to OpenCV's BGR Mat.