VideoPlaybackStrategy.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
30// OpenCV 2
31#include <opencv2/highgui/highgui.hpp>
32
33// VisionX
35
37{
38 /**
39 * Strategy to play back OpenCV supported common video files like .avi
40 */
42} // namespace visionx::imrec::strats
43
46{
47
48private:
49 /**
50 * @brief Path to the recording file
51 */
52 std::filesystem::path filePath;
53
54 /**
55 * @brief OpenCV VideoCapture object
56 */
57 cv::VideoCapture videoCapture;
58
59 /**
60 * @brief FPS of the recording (cv::VideoCapture::get is not const)
61 */
62 unsigned int fps;
63
64 /**
65 * @brief Current frame of the recording (cv::VideoCapture::get is not const)
66 */
67 unsigned int currentFrame;
68
69 /**
70 * @brief Frame height of the recording (cv::VideoCapture::get is not const)
71 */
72 unsigned int frameHeight;
73
74 /**
75 * @brief Frame width of the recording (cv::VideoCapture::get is not const)
76 */
77 unsigned int frameWidth;
78
79 /**
80 * @brief Amount of frames in the recording (cv::VideoCapture::get is not const)
81 */
82 unsigned int frameCount;
83
84public:
85 /**
86 * @brief Default constructor to manually setup later
87 */
89
90 /**
91 * @brief Constructor initialising the playback immediately
92 * @param filePath Path to the recording
93 */
94 VideoPlaybackStrategy(const std::filesystem::path& filePath);
95
96 /**
97 * @brief Destructor
98 */
99 virtual ~VideoPlaybackStrategy() override;
100
101 /**
102 * @brief Indicates whether the instance is configured to be able to play back
103 * @return True if it is playing back, false otherwise
104 */
105 virtual bool isPlayingBack() const override;
106
107 /**
108 * @brief Gets the amount of frames per second of the recording
109 * @return Amount of frames per second of the recording
110 */
111 virtual unsigned int getFps() const override;
112
113 /**
114 * @brief Gets the total amout of frames in the recording
115 * @return Total amount of frames in the recording
116 */
117 virtual unsigned int getFrameCount() const override;
118
119 /**
120 * @brief Gets the height of a frame in pixel
121 * @return Height of a frame in pixel
122 */
123 virtual unsigned int getFrameHeight() const override;
124
125 /**
126 * @brief Gets the width of a frame in pixel
127 * @return Width of a frame in pixel
128 */
129 virtual unsigned int getFrameWidth() const override;
130
131 /**
132 * @brief Sets the frame from there the playback should resume afterwards (seek)
133 * @param frame Frame from where the playback should be resumed (e.g. "0" to replay from the beginning)
134 */
135 virtual void setCurrentFrame(unsigned int frame) override;
136
137 /**
138 * @brief Gets the current frame index of the playback
139 * @return The current frame index
140 */
141 virtual unsigned int getCurrentFrame() const override;
142
143 /**
144 * @brief Indicates whether the recording has a consecutive frame
145 * @return True, if there is a consecutive frame, false otherwise
146 */
147 virtual bool hasNextFrame() const override;
148
149 /**
150 * @brief Starts the playback
151 * @param filePath Path to the recording to play back
152 */
153 virtual void startPlayback(const std::filesystem::path& filePath) override;
154
155 /**
156 * @brief Writes the next frame into a buffer of any form (RGB)
157 * @param buffer Output parameter where the frame data of the next frame should be written to
158 * @return True on success, false otherwise (no consecutive frame, error while loading frame)
159 */
160 virtual bool getNextFrame(void* buffer) override;
161
162 /**
163 * @brief Writes the next frame into an IVT CByteImage buffer (RGB)
164 * @param buffer Output parameter where the frame data of the next frame should be written to
165 * @return True on success, false otherwise (no consecutive frame, error while loading frame)
166 */
167 virtual bool getNextFrame(::CByteImage& buffer) override;
168
169 /**
170 * @brief Writes the next frame into an OpenCV Mat buffer (BGR)
171 * @param buffer Output parameter where the frame data of the next frame should be written to
172 * @return True on success, false otherwise (no consecutive frame, error while loading frame)
173 */
174 virtual bool getNextFrame(cv::Mat& buffer) override;
175
176 /**
177 * @brief Stops the playback
178 */
179 virtual void stopPlayback() override;
180};
virtual void setCurrentFrame(unsigned int frame) override
Sets the frame from there the playback should resume afterwards (seek)
virtual void stopPlayback() override
Stops the playback.
virtual unsigned int getFrameWidth() const override
Gets the width of a frame in pixel.
virtual unsigned int getFps() const override
Gets the amount of frames per second of the recording.
virtual bool hasNextFrame() const override
Indicates whether the recording has a consecutive frame.
virtual unsigned int getFrameCount() const override
Gets the total amout of frames in the recording.
virtual unsigned int getCurrentFrame() const override
Gets the current frame index of the playback.
virtual bool getNextFrame(void *buffer) override
Writes the next frame into a buffer of any form (RGB)
virtual void startPlayback(const std::filesystem::path &filePath) override
Starts the playback.
virtual bool isPlayingBack() const override
Indicates whether the instance is configured to be able to play back.
VideoPlaybackStrategy()
Default constructor to manually setup later.
virtual unsigned int getFrameHeight() const override
Gets the height of a frame in pixel.