ImageSequencePlaybackStrategy.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 <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 #pragma once
25 
26 
27 // STD/STL
28 #include <filesystem>
29 #include <string>
30 #include <vector>
31 
32 // VisionX
34 
35 namespace visionx::imrec::strats
36 {
37  class ImageSequencePlaybackStrategy;
38 }
39 
42 {
43 
44 private:
45  /**
46  * @brief Flag to indicate whether the instance is configured for playback or not
47  */
48  bool playingBack;
49 
50  /**
51  * @brief Index of the current frame
52  */
53  unsigned int currentFrame;
54 
55  /**
56  * @brief Total amount of frames
57  */
58  unsigned int frameCount;
59 
60  /**
61  * @brief Base path of the recordig frame files
62  */
63  std::filesystem::path basePath;
64 
65  /**
66  * @brief Prefix of an image file which must match to be considered a frame
67  */
68  std::string requiredPrefix;
69 
70  /**
71  * @brief Suffix of an image file which must match to be considered a frame
72  */
73  std::string requiredSuffix;
74 
75  /**
76  * @brief Sorted list of each frame in the image sequence
77  */
78  std::vector<std::filesystem::path> framePaths;
79 
80  /**
81  * @brief Height of an individual frame in pixel
82  */
83  unsigned int frameHeight;
84 
85  /**
86  * @brief Width of an individual frame in pixel
87  */
88  unsigned int frameWidth;
89 
90 public:
91  /**
92  * @brief Default constructor to manually setup later
93  */
95 
96  /**
97  * @brief Constructor initialising the playback immediately
98  * @param filePath Path to the recording
99  */
100  ImageSequencePlaybackStrategy(const std::filesystem::path& filePath);
101 
102  /**
103  * @brief Destructor
104  */
105  virtual ~ImageSequencePlaybackStrategy() override;
106 
107  /**
108  * @brief Indicates whether the instance is configured to be able to play back
109  * @return True if it is playing back, false otherwise
110  */
111  virtual bool isPlayingBack() const override;
112 
113  /**
114  * @brief Gets the amount of frames per second of the recording
115  * @return Amount of frames per second of the recording
116  */
117  virtual unsigned int getFps() const override;
118 
119  /**
120  * @brief Gets the total amout of frames in the recording
121  * @return Total amount of frames in the recording
122  */
123  virtual unsigned int getFrameCount() const override;
124 
125  /**
126  * @brief Gets the height of a frame in pixel
127  * @return Height of a frame in pixel
128  */
129  virtual unsigned int getFrameHeight() const override;
130 
131  /**
132  * @brief Gets the width of a frame in pixel
133  * @return Width of a frame in pixel
134  */
135  virtual unsigned int getFrameWidth() const override;
136 
137  /**
138  * @brief Sets the frame from there the playback should resume afterwards (seek)
139  * @param frame Frame from where the playback should be resumed (e.g. "0" to replay from the beginning)
140  */
141  virtual void setCurrentFrame(unsigned int frame) override;
142 
143  /**
144  * @brief Gets the current frame index of the playback
145  * @return The current frame index
146  */
147  virtual unsigned int getCurrentFrame() const override;
148 
149  /**
150  * @brief Indicates whether the recording has a consecutive frame
151  * @return True, if there is a consecutive frame, false otherwise
152  */
153  virtual bool hasNextFrame() const override;
154 
155  /**
156  * @brief Starts the playback
157  * @param filePath Path to the recording to play back
158  */
159  virtual void startPlayback(const std::filesystem::path& filePath) override;
160 
161  /**
162  * @brief Writes the next frame into a buffer of any form (RGB)
163  * @param buffer Output parameter where the frame data of the next frame should be written to
164  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
165  */
166  virtual bool getNextFrame(void* buffer) override;
167 
168  /**
169  * @brief Writes the next frame into an IVT CByteImage buffer (RGB)
170  * @param buffer Output parameter where the frame data of the next frame should be written to
171  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
172  */
173  virtual bool getNextFrame(::CByteImage& buffer) override;
174 
175  /**
176  * @brief Writes the next frame into an OpenCV Mat buffer (BGR)
177  * @param buffer Output parameter where the frame data of the next frame should be written to
178  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
179  */
180  virtual bool getNextFrame(cv::Mat& buffer) override;
181 
182  /**
183  * @brief Stops the playback
184  */
185  virtual void stopPlayback() override;
186 
187 private:
188  /**
189  * @brief Initialises the base path, and the required prefix and suffix for each frame file
190  * @param filePath Given path
191  */
192  void initBasePathPrefixSuffix(const std::filesystem::path& filePath);
193 
194  /**
195  * @brief Initialises each frame path given the requirements
196  */
197  void initFramePaths();
198 
199  /**
200  * @brief Initialise the height and width of an individual frame
201  */
202  void initFrameDimensions();
203 };
visionx::imrec::strats::ImageSequencePlaybackStrategy::getCurrentFrame
virtual unsigned int getCurrentFrame() const override
Gets the current frame index of the playback.
Definition: ImageSequencePlaybackStrategy.cpp:108
AbstractPlaybackStrategy.h
visionx::imrec::strats::ImageSequencePlaybackStrategy::startPlayback
virtual void startPlayback(const std::filesystem::path &filePath) override
Starts the playback.
Definition: ImageSequencePlaybackStrategy.cpp:120
visionx::imrec::strats::ImageSequencePlaybackStrategy::hasNextFrame
virtual bool hasNextFrame() const override
Indicates whether the recording has a consecutive frame.
Definition: ImageSequencePlaybackStrategy.cpp:114
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFrameWidth
virtual unsigned int getFrameWidth() const override
Gets the width of a frame in pixel.
Definition: ImageSequencePlaybackStrategy.cpp:96
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFps
virtual unsigned int getFps() const override
Gets the amount of frames per second of the recording.
Definition: ImageSequencePlaybackStrategy.cpp:74
visionx::imrec::strats::ImageSequencePlaybackStrategy
Definition: ImageSequencePlaybackStrategy.h:40
visionx::imrec::strats::ImageSequencePlaybackStrategy::~ImageSequencePlaybackStrategy
virtual ~ImageSequencePlaybackStrategy() override
Destructor.
Definition: ImageSequencePlaybackStrategy.cpp:62
visionx::imrec::strats::ImageSequencePlaybackStrategy::ImageSequencePlaybackStrategy
ImageSequencePlaybackStrategy()
Default constructor to manually setup later.
Definition: ImageSequencePlaybackStrategy.cpp:46
visionx::imrec::strats::ImageSequencePlaybackStrategy::stopPlayback
virtual void stopPlayback() override
Stops the playback.
Definition: ImageSequencePlaybackStrategy.cpp:186
visionx::imrec::strats
Definition: ChunkedImageSequencePlaybackStrategy.h:37
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFrameHeight
virtual unsigned int getFrameHeight() const override
Gets the height of a frame in pixel.
Definition: ImageSequencePlaybackStrategy.cpp:90
visionx::imrec::strats::ImageSequencePlaybackStrategy::setCurrentFrame
virtual void setCurrentFrame(unsigned int frame) override
Sets the frame from there the playback should resume afterwards (seek)
Definition: ImageSequencePlaybackStrategy.cpp:102
visionx::imrec::strats::ImageSequencePlaybackStrategy::getNextFrame
virtual bool getNextFrame(void *buffer) override
Writes the next frame into a buffer of any form (RGB)
Definition: ImageSequencePlaybackStrategy.cpp:133
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFrameCount
virtual unsigned int getFrameCount() const override
Gets the total amout of frames in the recording.
Definition: ImageSequencePlaybackStrategy.cpp:84
visionx::imrec::AbstractPlaybackStrategy
Definition: AbstractPlaybackStrategy.h:50
visionx::imrec::strats::ImageSequencePlaybackStrategy::isPlayingBack
virtual bool isPlayingBack() const override
Indicates whether the instance is configured to be able to play back.
Definition: ImageSequencePlaybackStrategy.cpp:68