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/opencv.hpp>
44#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat)
45
46// Qt
47#include <QString>
48#include <QToolBar>
49
50// ArmarX
54
57
58// IVT
59#include <Image/ByteImage.h>
60
61// VisionX
64
65#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
66
71
72namespace visionx
73{
74 /**
75 \page VisionX-GuiPlugins-ImageMonitor ImageMonitor
76 \brief ...
77
78 \image html ImageMonitorGuiPlugin.bmp "The Image Monitor gui plugin"
79
80 API Documentation \ref ImageMonitorWidgetController
81
82 \see ImageMonitorGuiPlugin
83 */
84
85 /**
86 * \class ImageMonitorProperties
87 * \brief ImageMonitorProperties brief one line description
88 *
89 * Detailed description
90 */
92 {
93 public:
95
96 std::string providerName;
98 std::filesystem::path outputDirectory;
101 std::set<size_t> imagesToShow;
104 QStringList recordingMethods;
107 CompressionType compressionType;
109 };
110
111 using CByteImagePtr = std::shared_ptr<CByteImage>;
112 using ImageContainer = std::vector<CByteImagePtr>;
113
114 /*!
115 * \class ImageMonitorWidgetController
116 * \brief
117 */
119 public armarx::ArmarXComponentWidgetControllerTemplate<ImageMonitorWidgetController>,
121 {
122 Q_OBJECT
123
124 public:
126
127 // inherited from ArmarXWidgetController
128 QPointer<QWidget> getWidget() override;
129
130 static QString
132 {
133 return "VisionX.ImageMonitor";
134 }
135
136 static QIcon
138 {
139 return QIcon{"://icons/image_monitor.svg"};
140 }
141
142 static QIcon
144 {
145 return QIcon{"://icons/eye.svg"};
146 }
147
148 void loadSettings(QSettings* settings) override;
149 void saveSettings(QSettings* settings) override;
150
151 // inherited from ImageProcessor
152 void onInitImageProcessor() override;
153 void onConnectImageProcessor() override;
154 void onExitImageProcessor() override;
155 void process() override;
156
157 // properties
158 void applyProperties(ImageMonitorProperties properties);
159 ImageMonitorProperties getProperties();
160
161 // getters
162 ImageTransferStats getStatistics();
163
166 {
167 return imageProviderInfo;
168 }
169
170 const ImageContainer& getBufferedImage(unsigned int position, unsigned int& realPosition);
171
172 unsigned int
174 {
175 return imageBuffer.size();
176 }
177
178 // setters
179 void
180 setPlaying(bool playing)
181 {
182 this->playing = playing;
183 }
184
185 void
186 setBuffering(bool buffering)
187 {
188 this->writeImageBuffer = buffering;
189 }
190
191 void createSnapshot();
192
193 // ice
194 using Component::getIceManager;
195
196 /**
197 * @brief Start recording of the images to bmp-files. Each frame of
198 * each camera is one bmp-file. The names of the files contain a
199 * increasing sequence_number.
200 * @param fps Specifies the framerate of the recording. If set to -1
201 * the framerate of the source is used.
202 */
203 void startRecording();
204 void stopRecording();
205
206 // Qt signals
207 signals:
208 void imageProviderConnected(bool connected);
209 void recordingBufferEmpty(bool isEmpty);
210 void statisticsUpdated(const QString& statisticsString);
211
212 private:
213 void connectToProvider();
214 void disconnectFromProvider();
215 void updateStatistics();
216 void recordFrame();
217
218 private slots:
219 void hideControls(bool hide = true);
220
221 private:
222 // ui
223 QPointer<ImageMonitorWidget> widget;
224
225 // settings
226 ImageMonitorProperties properties;
227
228 // images
229 CByteImage** images;
230 unsigned int numberImages;
231
232 // provider
233 ImageProviderInterfacePrx imageProviderPrx;
234 visionx::ImageProviderInfo imageProviderInfo;
235
236 // recording
238
239 // image buffer
240 bool writeImageBuffer;
241 int bufferSize;
242 float bufferFps;
243 IceUtil::Time lastBufferTime;
244 boost::circular_buffer<ImageContainer> imageBuffer;
245 std::queue<std::vector<CByteImage*>> recordingBuffer;
246 std::recursive_mutex recordingBufferMutex;
247 bool writeRecordingBuffer = false;
248
249 // internals
250 bool connected;
251 bool playing;
252
253 std::recursive_mutex imageMutex;
254 FPSCounter fpsCounter;
255
256 QPointer<QToolBar> customToolbar;
257 QAction* viewingModeAction;
258
259 IceUtil::Time timeProvided, timeReceived;
261 std::vector<cv::Mat> outputBuffer;
262 std::vector<visionx::imrec::Recording> recorders;
263
264 std::map<float, std::vector<std::optional<armarx::DrawColor24Bit>>> depthToRgbLookUpTables;
265
266 // ArmarXWidgetController interface
267 public:
268 QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
269 std::string getAbsoluteOutputPath();
270 void convertToHeatMapDepthImage(CByteImage* image);
271 };
272} // 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