public_api.h
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 <c.dreher@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 #pragma once
25 
26 
27 // STD/STL
28 #include <filesystem>
29 #include <map>
30 
31 // ArmarX
34 
35 
36 class CByteImage;
37 
38 namespace cv
39 {
40  class Mat;
41 }
42 
43 namespace visionx::imrec
44 {
45 
46 
47  /**
48  * @brief Supported recording Formats.
49  *
50  * @note If you add new formats, also add them to the registry (declared in an anonymous
51  * namespace) in public_api.cpp.
52  */
53  enum class Format
54  {
63  };
64 
65 
66  enum class Framerate
67  {
68  static_fps,
70  };
71 
72 
73  enum class Compression
74  {
75  lossy,
76  lossless
77  };
78 
80  {
81  /**
82  * @brief Identifier to use for long-term storage purposes etc.
83  */
84  std::string id;
85 
86  /**
87  * @brief Human readable identifier for UI's or outputs. May change, so do not use as an
88  * identifier for long-term storage.
89  */
90  std::string hr_name;
91 
92  /**
93  * @brief Framerate handling
94  */
96 
97  /**
98  * @brief Compression handling
99  */
101  };
102 
103  const std::string& format2str(const Format format);
104 
105 
106  const std::string& format2hrstr(const Format format);
107 
108 
109  Format str2format(const std::string& format_str);
110 
111 
112  std::vector<Format> getFormats();
113 
114 
115  std::map<Format, RegistryEntry> getFormatsMap();
116 
117 
118  bool isFormatLossless(Format format);
119 
120 
121  bool isFormatDynamicFramerate(Format format);
122 
123 
124  /**
125  * @brief Instantiates and returns a new playback strategy which is capable of replaying the file or collection at path
126  * @param path Path to the recording file or collection (folder, glob, ...)
127  * @return Concrete playback strategy capable of replaying the recording at path
128  */
129  visionx::imrec::Playback newPlayback(const std::filesystem::path& path);
130 
131 
132  visionx::imrec::Recording newRecording(const std::filesystem::path& path,
133  const std::string& name,
134  const Format format,
135  double fps);
136 
137 
138  /**
139  * @brief Creates a new recording given the file extension and additional parameters
140  * @param filePath Path to where the recording file should be written to
141  * @param fps Amount of frames being recorded per second
142  * @return Recording object
143  */
144  visionx::imrec::Recording newRecording(const std::filesystem::path& filePath, double fps);
145 
146 
147  /**
148  * @brief Takes a snapshot using the default recording method for snapshots
149  * @param filePath Path to where the recording file should be written to
150  * @param image The image to be saved
151  */
152  void takeSnapshot(const CByteImage& image, const std::filesystem::path& filePath);
153 
154 
155  /**
156  * @brief Takes a snapshot using the default recording method for snapshots
157  * @param filePath Path to where the recording file should be written to
158  * @param image The image to be saved
159  */
160  void takeSnapshot(const cv::Mat& image, const std::filesystem::path& filePath);
161 
162 } // namespace visionx::imrec
visionx::imrec::Format::bmp_img_seq
@ bmp_img_seq
visionx::imrec::getFormatsMap
std::map< Format, RegistryEntry > getFormatsMap()
Definition: public_api.cpp:144
visionx::imrec::Format
Format
Supported recording Formats.
Definition: public_api.h:53
visionx::imrec::RegistryEntry::compression
Compression compression
Compression handling.
Definition: public_api.h:100
visionx::imrec::Framerate::dynamic_fps
@ dynamic_fps
AbstractPlaybackStrategy.h
visionx::imrec::getFormats
std::vector< Format > getFormats()
Definition: public_api.cpp:133
visionx::imrec::Format::avi_default
@ avi_default
visionx::imrec::isFormatLossless
bool isFormatLossless(Format format)
Definition: public_api.cpp:150
visionx::imrec::Format::png_fast_mt_img_seq
@ png_fast_mt_img_seq
visionx::imrec::Framerate::static_fps
@ static_fps
visionx::imrec::RegistryEntry
Definition: public_api.h:79
visionx::imrec::RegistryEntry::hr_name
std::string hr_name
Human readable identifier for UI's or outputs.
Definition: public_api.h:90
visionx::imrec::RegistryEntry::framerate
Framerate framerate
Framerate handling.
Definition: public_api.h:95
visionx::imrec::Compression
Compression
Definition: public_api.h:73
visionx::imrec::Playback
std::shared_ptr< visionx::imrec::AbstractPlaybackStrategy > Playback
Convenience alias for an instance of any playback strategy.
Definition: AbstractPlaybackStrategy.h:47
visionx::imrec::format2str
const std::string & format2str(const Format format)
Definition: public_api.cpp:109
visionx::imrec::Format::png_img_seq
@ png_img_seq
AbstractRecordingStrategy.h
visionx::imrec::Compression::lossless
@ lossless
visionx::imrec::takeSnapshot
void takeSnapshot(const CByteImage &image, const std::filesystem::path &filePath)
Takes a snapshot using the default recording method for snapshots.
Definition: public_api.cpp:267
visionx::imrec::Framerate
Framerate
Definition: public_api.h:66
visionx::imrec::format2hrstr
const std::string & format2hrstr(const Format format)
Definition: public_api.cpp:115
visionx::imrec::Format::png_fast_img_seq
@ png_fast_img_seq
visionx::imrec::newRecording
visionx::imrec::Recording newRecording(const std::filesystem::path &path, const std::string &name, const Format format, double fps)
Definition: public_api.cpp:194
visionx::imrec::Recording
std::shared_ptr< AbstractRecordingStrategy > Recording
Convenience alias for any recording strategy.
Definition: AbstractRecordingStrategy.h:179
visionx::imrec::str2format
Format str2format(const std::string &format_str)
Definition: public_api.cpp:121
visionx::imrec::newPlayback
visionx::imrec::Playback newPlayback(const std::filesystem::path &path)
Instantiates and returns a new playback strategy which is capable of replaying the file or collection...
Definition: public_api.cpp:162
visionx::imrec::Compression::lossy
@ lossy
visionx::imrec::Format::jpg_img_seq
@ jpg_img_seq
visionx::imrec::RegistryEntry::id
std::string id
Identifier to use for long-term storage purposes etc.
Definition: public_api.h:84
cv
Definition: helper.h:34
visionx::imrec
Definition: json_conversions.h:35
visionx::imrec::Format::png_mt_img_seq
@ png_mt_img_seq
visionx::imrec::Format::mp4_default
@ mp4_default
visionx::imrec::isFormatDynamicFramerate
bool isFormatDynamicFramerate(Format format)
Definition: public_api.cpp:156