AbstractSequencedRecordingStrategy.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package visionx::imrec
17 * @author Christian R. G. Dreher <christian.dreher@student.kit.edu>
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
24// Amount of frames per chunk
25#define CHUNK_SIZE 100
26
27
29
30
31// STD/STL
32#include <filesystem>
33
34// OpenCV 2
35#include <opencv2/opencv.hpp>
36
37// IVT
38#include <Image/ByteImage.h>
39
40// ArmarX
42
44
50
52 const std::filesystem::path& filePath,
53 const std::filesystem::path& ext) :
54 visionx::imrec::AbstractRecordingStrategy(filePath), m_ext{ext}
55{
56 // pass
57}
58
63
64void
66{
68 std::filesystem::path pathStem = getPath() / getStem();
69
70 ARMARX_CHECK_EXPRESSION(not std::filesystem::exists(pathStem)) << "Folder already exists";
71
72 std::filesystem::create_directory(pathStem);
73
74 writeMetadataLine("frames_per_chunk", "unsigned int", std::to_string(CHUNK_SIZE));
75 writeMetadataLine("extension", "string", getDotExtension().string());
76}
77
78std::filesystem::path
83
84std::filesystem::path
86{
87 std::filesystem::path path = getPath() / getStem();
88 return std::filesystem::canonical(path) / "metadata.csv";
89}
90
91std::filesystem::path
93 const unsigned int sequence_number,
94 const std::string& frame_name)
95{
96 const std::filesystem::path frame_filename = frame_name + getDotExtension().string();
97
98 if (sequence_number % CHUNK_SIZE == 0)
99 {
100 unsigned int chunk_number = sequence_number / CHUNK_SIZE;
101 m_frames_chunk = "chunk_" + std::to_string(chunk_number);
102 std::filesystem::create_directory(std::filesystem::canonical(getPath() / getStem()) /
103 m_frames_chunk);
104 }
105
106 return std::filesystem::canonical(getPath() / getStem() / m_frames_chunk) / frame_filename;
107}
virtual std::filesystem::path getPath() const
Gets the path to the recording without filename.
AbstractRecordingStrategy()
Default constructor to start the recording manually.
virtual std::filesystem::path getStem() const
Gets the stem of the configured file (filename without extension)
virtual void startRecording()
Starts the recording manually if constructed empty.
virtual void writeMetadataLine(const std::string &var_name, std::string_view var_type, std::string_view var_value)
std::filesystem::path getDotExtension() const override
Gets the extension plus preceeded dot of the configured file (e.g.
void startRecording() override
Starts the recording manually if constructed empty.
AbstractSequencedRecordingStrategy()
Default constructor to manually start the recording.
~AbstractSequencedRecordingStrategy() override
Destruct the recording strategy.
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.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
ArmarX headers.