ImageMonitorWidgetController.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 ObserverTest::
17* @author ( at kit dot edu)
18* @date
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 <mutex>
29#include <optional>
30// <filesystem> needs to be down here. Otherwise, for some reason,
31// the Qt AutoMoc will say: 'Parse error at "std"'
32#include <filesystem>
33#include <queue>
34#include <set>
35#include <string>
36#include <vector>
37
38
39// Boost
40#include <boost/circular_buffer.hpp>
41
42// OpenCV 2
43#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat)
44
45// Qt
46#include <QString>
47#include <QToolBar>
48
49// ArmarX
53
56
57// IVT
58#include <Image/ByteImage.h>
59
60// VisionX
63
64#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
65
70
71namespace visionx
72{
73 /**
74 \page VisionX-GuiPlugins-ImageMonitor ImageMonitor
75 \brief ...
76
77 \image html ImageMonitorGuiPlugin.bmp "The Image Monitor gui plugin"
78
79 API Documentation \ref ImageMonitorWidgetController
80
81 \see ImageMonitorGuiPlugin
82 */
83
84 /**
85 * \class ImageMonitorProperties
86 * \brief ImageMonitorProperties brief one line description
87 *
88 * Detailed description
89 */
91 {
92 public:
94
95 std::string providerName;
97 std::filesystem::path outputDirectory;
99 float bufferFps;
100 std::set<size_t> imagesToShow;
103 QStringList recordingMethods;
106 CompressionType compressionType;
108 };
109
110 using CByteImagePtr = std::shared_ptr<CByteImage>;
111 using ImageContainer = std::vector<CByteImagePtr>;
112
113 /*!
114 * \class ImageMonitorWidgetController
115 * \brief
116 */
118 public armarx::ArmarXComponentWidgetControllerTemplate<ImageMonitorWidgetController>,
120 {
121 Q_OBJECT
122
123 public:
125
126 // inherited from ArmarXWidgetController
127 QPointer<QWidget> getWidget() override;
128
129 static QString
131 {
132 return "VisionX.ImageMonitor";
133 }
134
135 static QIcon
137 {
138 return QIcon{"://icons/image_monitor.svg"};
139 }
140
141 static QIcon
143 {
144 return QIcon{"://icons/eye.svg"};
145 }
146
147 void loadSettings(QSettings* settings) override;
148 void saveSettings(QSettings* settings) override;
149
150 // inherited from ImageProcessor
151 void onInitImageProcessor() override;
152 void onConnectImageProcessor() override;
153 void onExitImageProcessor() override;
154 void process() override;
155
156 // properties
157 void applyProperties(ImageMonitorProperties properties);
158 ImageMonitorProperties getProperties();
159
160 // getters
161 ImageTransferStats getStatistics();
162
165 {
166 return imageProviderInfo;
167 }
168
169 const ImageContainer& getBufferedImage(unsigned int position, unsigned int& realPosition);
170
171 unsigned int
173 {
174 return imageBuffer.size();
175 }
176
177 // setters
178 void
179 setPlaying(bool playing)
180 {
181 this->playing = playing;
182 }
183
184 void
185 setBuffering(bool buffering)
186 {
187 this->writeImageBuffer = buffering;
188 }
189
190 void createSnapshot();
191
192 // ice
193 using Component::getIceManager;
194
195 /**
196 * @brief Start recording of the images to bmp-files. Each frame of
197 * each camera is one bmp-file. The names of the files contain a
198 * increasing sequence_number.
199 * @param fps Specifies the framerate of the recording. If set to -1
200 * the framerate of the source is used.
201 */
202 void startRecording();
203 void stopRecording();
204
205 // Qt signals
206 signals:
207 void imageProviderConnected(bool connected);
208 void recordingBufferEmpty(bool isEmpty);
209 void statisticsUpdated(const QString& statisticsString);
210
211 private:
212 void connectToProvider();
213 void disconnectFromProvider();
214 void updateStatistics();
215 void recordFrame();
216
217 private slots:
218 void hideControls(bool hide = true);
219
220 private:
221 // ui
222 QPointer<ImageMonitorWidget> widget;
223
224 // settings
225 ImageMonitorProperties properties;
226
227 // images
228 CByteImage** images;
229 unsigned int numberImages;
230
231 // provider
232 ImageProviderInterfacePrx imageProviderPrx;
233 visionx::ImageProviderInfo imageProviderInfo;
234
235 // recording
237
238 // image buffer
239 bool writeImageBuffer;
240 int bufferSize;
241 float bufferFps;
242 IceUtil::Time lastBufferTime;
243 boost::circular_buffer<ImageContainer> imageBuffer;
244 std::queue<std::vector<CByteImage*>> recordingBuffer;
245 std::recursive_mutex recordingBufferMutex;
246 bool writeRecordingBuffer = false;
247
248 // internals
249 bool connected;
250 bool playing;
251
252 std::recursive_mutex imageMutex;
253 FPSCounter fpsCounter;
254
255 QPointer<QToolBar> customToolbar;
256 QAction* viewingModeAction;
257
258 IceUtil::Time timeProvided, timeReceived;
260 std::vector<cv::Mat> outputBuffer;
261 std::vector<visionx::imrec::Recording> recorders;
262
263 std::map<float, std::vector<std::optional<armarx::DrawColor24Bit>>> depthToRgbLookUpTables;
264
265 // ArmarXWidgetController interface
266 public:
267 QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
268 std::string getAbsoluteOutputPath();
269 void convertToHeatMapDepthImage(CByteImage* image);
270 };
271} // namespace visionx
#define ARMARXCOMPONENT_IMPORT_EXPORT
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
This filters allows to filter with an unstable frequency by considering only the valus in a specified...
The FPSCounter class provides methods for calculating the frames per second (FPS) count in periodic t...
Definition FPSCounter.h:37
ImageMonitorProperties brief one line description.
void imageProviderConnected(bool connected)
void statisticsUpdated(const QString &statisticsString)
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
The ImageTransferStats class provides information on the connection between ImageProvider and ImagePr...
ArmarX headers.
std::shared_ptr< CByteImage > CByteImagePtr
std::vector< CByteImagePtr > ImageContainer