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
55 
56 // IVT
57 #include <Image/ByteImage.h>
58 
59 // VisionX
66 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
67 
68 
69 namespace visionx
70 {
71  /**
72  \page VisionX-GuiPlugins-ImageMonitor ImageMonitor
73  \brief ...
74 
75  \image html ImageMonitorGuiPlugin.bmp "The Image Monitor gui plugin"
76 
77  API Documentation \ref ImageMonitorWidgetController
78 
79  \see ImageMonitorGuiPlugin
80  */
81 
82  /**
83  * \class ImageMonitorProperties
84  * \brief ImageMonitorProperties brief one line description
85  *
86  * Detailed description
87  */
89  {
90  public:
91 
93 
94  std::string providerName;
95  int frameRate;
96  std::filesystem::path outputDirectory;
98  float bufferFps;
99  std::set<size_t> imagesToShow;
102  QStringList recordingMethods;
105  CompressionType compressionType;
107  };
108 
109  using CByteImagePtr = std::shared_ptr<CByteImage>;
110  using ImageContainer = std::vector<CByteImagePtr>;
111 
112  /*!
113  * \class ImageMonitorWidgetController
114  * \brief
115  */
117  public armarx::ArmarXComponentWidgetControllerTemplate<ImageMonitorWidgetController>,
119  {
120  Q_OBJECT
121 
122  public:
124 
125  // inherited from ArmarXWidgetController
126  QPointer<QWidget> getWidget() override;
127  static QString GetWidgetName()
128  {
129  return "VisionX.ImageMonitor";
130  }
131  static QIcon GetWidgetIcon()
132  {
133  return QIcon {"://icons/image_monitor.svg"};
134  }
135  static QIcon GetWidgetCategoryIcon()
136  {
137  return QIcon {"://icons/eye.svg"};
138  }
139 
140  void loadSettings(QSettings* settings) override;
141  void saveSettings(QSettings* settings) override;
142 
143  // inherited from ImageProcessor
144  void onInitImageProcessor() override;
145  void onConnectImageProcessor() override;
146  void onExitImageProcessor() override;
147  void process() override;
148 
149  // properties
150  void applyProperties(ImageMonitorProperties properties);
151  ImageMonitorProperties getProperties();
152 
153  // getters
154  ImageTransferStats getStatistics();
156  {
157  return imageProviderInfo;
158  }
159  const ImageContainer& getBufferedImage(unsigned int position, unsigned int& realPosition);
160  unsigned int getBufferedImageCount()
161  {
162  return imageBuffer.size();
163  }
164 
165  // setters
166  void setPlaying(bool playing)
167  {
168  this->playing = playing;
169  }
170  void setBuffering(bool buffering)
171  {
172  this->writeImageBuffer = buffering;
173  }
174 
175  void createSnapshot();
176 
177  // ice
178  using Component::getIceManager;
179 
180  /**
181  * @brief Start recording of the images to bmp-files. Each frame of
182  * each camera is one bmp-file. The names of the files contain a
183  * increasing sequence_number.
184  * @param fps Specifies the framerate of the recording. If set to -1
185  * the framerate of the source is used.
186  */
187  void startRecording();
188  void stopRecording();
189 
190  // Qt signals
191  signals:
192  void imageProviderConnected(bool connected);
193  void recordingBufferEmpty(bool isEmpty);
194  void statisticsUpdated(const QString& statisticsString);
195 
196  private:
197  void connectToProvider();
198  void disconnectFromProvider();
199  void updateStatistics();
200  void recordFrame();
201 
202  private slots:
203  void hideControls(bool hide = true);
204 
205  private:
206  // ui
207  QPointer<ImageMonitorWidget> widget;
208 
209  // settings
210  ImageMonitorProperties properties;
211 
212  // images
213  CByteImage** images;
214  unsigned int numberImages;
215 
216  // provider
217  ImageProviderInterfacePrx imageProviderPrx;
218  visionx::ImageProviderInfo imageProviderInfo;
219 
220  // recording
222 
223  // image buffer
224  bool writeImageBuffer;
225  int bufferSize;
226  float bufferFps;
227  IceUtil::Time lastBufferTime;
228  boost::circular_buffer<ImageContainer > imageBuffer;
229  std::queue<std::vector<CByteImage*>> recordingBuffer;
230  std::recursive_mutex recordingBufferMutex;
231  bool writeRecordingBuffer = false;
232 
233  // internals
234  bool connected;
235  bool playing;
236 
237  std::recursive_mutex imageMutex;
238  FPSCounter fpsCounter;
239 
240  QPointer<QToolBar> customToolbar;
241  QAction* viewingModeAction;
242 
243  IceUtil::Time timeProvided, timeReceived;
245  std::vector<cv::Mat> outputBuffer;
246  std::vector<visionx::imrec::Recording> recorders;
247 
248  std::map<float, std::vector<std::optional<armarx::DrawColor24Bit>>> depthToRgbLookUpTables;
249 
250  // ArmarXWidgetController interface
251  public:
252  QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
253  std::string getAbsoluteOutputPath();
254  void convertToHeatMapDepthImage(CByteImage* image);
255 
256  };
257 }
visionx::ImageMonitorProperties::recordDepthRaw
bool recordDepthRaw
Definition: ImageMonitorWidgetController.h:101
ImageMonitorWidget.h
TimeWindowAverageFilter.h
visionx::ImageMonitorProperties::ImageMonitorProperties
ImageMonitorProperties()
Definition: ImageMonitorWidgetController.cpp:84
visionx::ImageMonitorWidgetController::getImageProviderInfo
ImageProviderInfo getImageProviderInfo()
Definition: ImageMonitorWidgetController.h:155
AverageFilter.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:87
visionx::ImageMonitorWidgetController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: ImageMonitorWidgetController.h:131
visionx::ImageTransferStats
The ImageTransferStats class provides information on the connection between ImageProvider and ImagePr...
Definition: ImageProcessor.h:441
visionx::ImageMonitorProperties::maxDepthmm
int maxDepthmm
Definition: ImageMonitorWidgetController.h:104
visionx::ImageMonitorProperties::imageBufferSize
int imageBufferSize
Definition: ImageMonitorWidgetController.h:97
visionx::ImageMonitorProperties::depthImageIndex
int depthImageIndex
Definition: ImageMonitorWidgetController.h:103
PeriodicTask.h
visionx::ImageMonitorWidgetController::GetWidgetName
static QString GetWidgetName()
Definition: ImageMonitorWidgetController.h:127
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
visionx::ImageMonitorWidgetController
Definition: ImageMonitorWidgetController.h:116
visionx::ImageMonitorProperties::imagesToShow
std::set< size_t > imagesToShow
Definition: ImageMonitorWidgetController.h:99
visionx::ImageProviderInfo
Definition: ImageProcessor.h:466
armarx::rtfilters::TimeWindowAverageFilter
This filters allows to filter with an unstable frequency by considering only the valus in a specified...
Definition: TimeWindowAverageFilter.h:36
visionx::ImageMonitorProperties::frameRate
int frameRate
Definition: ImageMonitorWidgetController.h:95
ArmarXGuiPlugin.h
imrec.h
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
ImageProcessor.h
visionx::ImageMonitorProperties::recordingMethods
QStringList recordingMethods
Definition: ImageMonitorWidgetController.h:102
visionx::ImageMonitorProperties::providerName
std::string providerName
Definition: ImageMonitorWidgetController.h:94
visionx::ImageContainer
std::vector< CByteImagePtr > ImageContainer
Definition: ImageMonitorWidgetController.h:110
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
visionx::ImageMonitorProperties::controlsHidden
bool controlsHidden
Definition: ImageMonitorWidgetController.h:100
Component.h
IceUtil::Handle
Definition: forward_declarations.h:29
visionx::ImageMonitorWidgetController::getBufferedImageCount
unsigned int getBufferedImageCount()
Definition: ImageMonitorWidgetController.h:160
visionx::ImageMonitorWidgetController::setBuffering
void setBuffering(bool buffering)
Definition: ImageMonitorWidgetController.h:170
visionx::ImageMonitorProperties::outputDirectory
std::filesystem::path outputDirectory
Definition: ImageMonitorWidgetController.h:96
visionx::ImageMonitorProperties
ImageMonitorProperties brief one line description.
Definition: ImageMonitorWidgetController.h:88
visionx::ImageMonitorProperties::bufferFps
float bufferFps
Definition: ImageMonitorWidgetController.h:98
FPSCounter.h
visionx::FPSCounter
The FPSCounter class provides methods for calculating the frames per second (FPS) count in periodic t...
Definition: FPSCounter.h:36
visionx::CByteImagePtr
std::shared_ptr< CByteImage > CByteImagePtr
Definition: ImageMonitorWidgetController.h:109
visionx::ImageMonitorProperties::compressionType
CompressionType compressionType
Definition: ImageMonitorWidgetController.h:105
visionx::ImageMonitorWidgetController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Definition: ImageMonitorWidgetController.h:135
visionx::ImageMonitorProperties::compressionQuality
int compressionQuality
Definition: ImageMonitorWidgetController.h:106
visionx::ImageMonitorWidgetController::setPlaying
void setPlaying(bool playing)
Definition: ImageMonitorWidgetController.h:166
ImportExportComponent.h