iVS3D v2.0.0
Loading...
Searching...
No Matches
semanticsegmentation.h
1#ifndef NTHFRAME_H
2#define NTHFRAME_H
3
12#include <QObject>
13#include <QString>
14#include <QTimer>
15#include <QDir>
16#include <QException>
17#include <QCoreApplication>
18#include <QThread>
19#include <QMutex>
20#include <QMutexLocker>
21#include <QTranslator>
22
23#include <QDebug>
24
25#include "semanticsegmentation_global.h"
26#include "itransform.h"
27#include "settingswidget.h"
28
29#include <iostream>
30#include <fstream>
31
32#include <opencv2/opencv.hpp>
33#include <opencv2/core/ocl.hpp>
34
35#include <iostream>
36#include <iomanip>
37#include <regex>
38
39#include <NeuralNetFactory.h>
40#include <Tensor.h>
41#include <NeuralUtil.h>
42
43#define MODEL_PATH "/plugins/resources/neural_network_models"
44#define HW_NAME(x) x ? "Using GPU (cuda)" : "Using CPU"
45#define USED_MODEL "Used Model"
46#define SELECTED_CLASSES "Selected classes"
47
62class SEMANTICSEGMENTATION_EXPORT SemanticSegmentation : public ITransform
63{
64 Q_OBJECT
65 Q_PLUGIN_METADATA(IID "iVS3D.ITransform") // implement interface as plugin, use the iid as identifier
66 Q_INTERFACES(ITransform) // declare this as implementation of ITransform interface
67
68public:
74
82 QWidget* getSettingsWidget(QWidget *parent) override;
83
88 QString getName() const override;
89
94 ITransform *copy() override;
95
108 TransformResult transform(uint idx, const cv::Mat &img, const Resolution &resolution, const ROI &roi) override;
109
114 void enableCuda(bool enabled) override;
115
120 void setSettings(QMap<QString, QVariant> settings) override;
121
126 QMap<QString, QVariant> getSettings() override;
127
128 void deactivate() override;
129
130signals:
137 void sig_classesAndColorsChanged(QStringList classes, QColorList colors, QBoolList selectedClasses);
138
145 void sig_message(QString processor, QString message = "", bool active = true);
146
147 void sig_error(QString message);
148
149private slots:
150 // --- slots for signals from SettingsWidget ---
151 void slot_ONNXindexChanged(int n);
152 void slot_selectedClassesChanged(QBoolList classes);
153 void slot_blendAlphaChanged(float alpha);
154
155private:
157 {
158 QString name; // Name of the class
159 QColor color; // Color for the class in the semantic map
160 };
161
163 {
164 std::vector<float> mean, std; // Mean and standard deviation for normalization
165 std::vector<ClassInfo> classes; // Classes with their colors for the model
166 } m_modelInfo;
167
168 bool loadModelInfo();
169
170 // --- gui data
171 SettingsWidget *m_settingsWidget; // settings widget for this ITransform
172 float m_blendAlpha; // alpha for semantic map overlay
173 bool m_guiUpToDate; // is true if gui is up to date, used to avoid unnessecary updates
174 void sendGuiPreview();
175
176 // --- ONNX model data ---
177 QStringList m_ONNXmodelList; // model names
178 NN::NeuralNetPtr m_model; // active model
179 int m_ONNXmodelIdx; // index of selected model in m_ONNXmodelList
180 QBoolList m_ONNXselectedClasses;// bool for each class of selected model (true if class selected)
181
182 // --- Buffer for image, nn score, segmentation and mask ---
183 uint m_imageIdx;
184 cv::Mat m_originalImage;
185 cv::Mat m_image;
186 Resolution m_resolution;
187 ROI m_roi;
188 NN::Tensor m_segmentationClasses;
189 cv::Mat m_segmentationColorized;
190 cv::Mat m_segmentationMask;
191 // --- use CUDA acceleration ---
192 bool m_useCuda;
193 // --- Widget sync ---
194 bool m_updateClasses = true; //Disable updates if classes are set manuel
195
196 // --- blend two images using an alpha value ---
197 void alphaBlend(const cv::Mat &foreground,const cv::Mat &background, cv::Mat &destionation, float alpha);
198
199 bool computeColorization();
200 bool computeMask();
201
202 Error createError(const QString &message);
203 QMutex m_mutex;
204};
205
206#endif // NTHFRAME_H
Factory class for creating NeuralNet instances.
Contains the Tensor class for representing N-dimensional arrays with various data types.
Definition ierror.h:7
The ITransform interface is used for algorithms to create additional image files from the source imag...
Definition itransform.h:88
virtual TransformResult transform(uint idx, const cv::Mat &img, const Resolution &resolution, const ROI &roi)=0
transform generates additional images from the given image. The signal sendToGui can be used to updat...
virtual QMap< QString, QVariant > getSettings()=0
getter for plugin's settings
virtual void setSettings(QMap< QString, QVariant > settings)=0
setter for plugin's settings
virtual QString getName() const =0
getName returns the display name for the plugin.
virtual ITransform * copy()=0
copy creates a new ITransform instance which is a deep copy.
virtual QWidget * getSettingsWidget(QWidget *parent)=0
getSettingsWidget is provides an QWidget to display plugin specific settings to the user....
virtual void enableCuda(bool enabled)=0
enableCuda enables use of the CUDA api to accelerate computations.
virtual void deactivate()
deactivate will be called when the plugin is no longer used, i.e. when the user deselects it in the s...
Definition itransform.h:153
A Tensor represents a N-dimensional array containing elements of the same type. Can be used as input ...
Definition Tensor.h:201
The ROI class manages a region of interest represented as a rectangle in the [0,1]x[0,...
Definition roi.h:21
The Resolution class encapsulates an image resolution (width and height). It provides functionality f...
Definition resolution.h:17
The SemanticSegmentation class is used to create binary masks for the reconstruction....
Definition semanticsegmentation.h:63
void sig_classesAndColorsChanged(QStringList classes, QColorList colors, QBoolList selectedClasses)
[signal] sig_classesAndColorsChanged is emitted if a new model with different classes and colors is s...
void sig_message(QString processor, QString message="", bool active=true)
[signal] sig_message is emmitted if the algorithm has a message for the user to display.
The SettingsWidget class provides user access to the parameters of SemanticSegmentation....
Definition settingswidget.h:44
std::shared_ptr< NeuralNet > NeuralNetPtr
Smart pointer type for managing NeuralNet instances.
Definition NeuralNet.h:95
Definition semanticsegmentation.h:157
Definition semanticsegmentation.h:163