iVS3D v2.0.0
Loading...
Searching...
No Matches
visualSimilarity.h
1#ifndef VISUALSIMILARITY_H
2#define VISUALSIMILARITY_H
3
13#include <QObject>
14#include <QWidget>
15#include <QString>
16#include <QMap>
17#include <QLayout>
18#include <QLabel>
19#include <QComboBox>
20#include <QSpinBox>
21#include <QPushButton>
22#include <QSpacerItem>
23#include <QSizePolicy>
24#include <QTranslator>
25#include <QCoreApplication>
26#include <QDialog>
27#include <QElapsedTimer>
28#include <QDebug>
29#include <QDir>
30#include <QtConcurrent>
31
32#include <opencv2/core.hpp>
33#include <opencv2/opencv.hpp>
34#include <opencv2/dnn.hpp>
35#include <opencv2/imgcodecs.hpp>
36#include <opencv2/imgproc.hpp>
37#include <opencv2/tracking/tracking_by_matching.hpp>
38
39#include <NeuralNetFactory.h>
40
41#include "ialgorithm.h"
42#include "reader.h"
43#include "progressable.h"
44#include "signalobject.h"
45
46#define RESSOURCE_PATH "/plugins/resources/neural_network_models/"
47#define MEM_THRESEHOLD 0.8f
48#define MAX_BATCH 100
49#define NN_STD {0.229, 0.224, 0.225}
50#define NN_MEAN {0.485, 0.456, 0.406}
51
52// visuals
53#define DESCRIPTION_STYLE "color: rgb(58, 58, 58); border-left: 6px solid rgb(58, 58, 58); border-top-right-radius: 5px; border-bottom-right-radius: 5px; background-color: lightblue;"
54#define UI_FRAMEREDUCTION_NAME QObject::tr("Select one frame every K framese")
55#define UI_FRAMEREDUCTION_DESC QObject::tr("Reduces the amount of selected frames by the factor K.")
56#define UI_NNNAME_NAME QObject::tr("Selected Neural Network")
57#define UI_NNNAME_DESC QObject::tr("The drop-down shows all files in the folder plugins/ressources/neural_network_models/ that follow the format ImageEmbedding_NAME_DIMENSION_WIDHTxHEIGHT.onnx")
58#define UI_NNNAME_BT_DESC QObject::tr("Resets the drop-Down and reloads available neural networks.")
59
60// json settings
61#define FRAMEREDUCTION_JSON_NAME "K"
62#define NNNAME_JSON_NAME "NN-Name"
63
64// log file
65#define LF_TIMER_KEYFRAMES "keyframeSelection"
66#define LF_TTHRESHOLD "tDistThreshold"
67#define LF_RESULT_INFO_TAG "result_info"
68#define LF_COMPUTE_INFO_TAG "compute_info"
69#define LF_SELECTION_INFO_TAG "selection_info"
70#define LF_TIMER_NN "NN feeding timer"
71#define LF_TIMER_KMEANS "kMeans timer"
72#define LF_TIMER_BUFFER "safe buffer timer"
73
74// buffer
75#define BUFFER_NAME_FEATURES "DeepVisSimilarityFeatureVector"
76#define BUFFER_FEATURE_DELIMITER_X ","
77#define BUFFER_FEATURE_DELIMITER_Y ";"
78#define BUFFER_NAME_IDX "DeepVisSimilarityIdx"
79
92{
93 Q_OBJECT
94 Q_PLUGIN_METADATA(IID "iVS3D.IAlgorithm") // implement interface as plugin, use the iid as identifier
95 Q_INTERFACES(IAlgorithm) // declare this as implementation of IAlgorithm interface
96
97public:
100
105 QWidget* getSettingsWidget(QWidget *parent) override;
106
119 std::vector<uint> sampleImages(const std::vector<unsigned int> &imageList, Progressable *receiver, volatile bool *stopped, bool useCuda, LogFileParent* logFile) override;
124 QString getName() const override;
131 void initialize(Reader* reader, QMap<QString, QVariant> buffer, signalObject* sigObj) override;
136 void setSettings(QMap<QString, QVariant> settings) override;
145 QMap<QString, QVariant> generateSettings(Progressable *receiver, bool useCuda, volatile bool* stopped) override;
151 QMap<QString, QVariant> getSettings() override;
152
153
154private slots:
155 void slot_selectedNNChanged(QString nnName);
156 void slot_reloadNN(int index);
157
158private:
159 // functions
160 static void displayProgress(Progressable *p, int progress, QString msg);
161 static void displayMessage(Progressable *p, QString msg);
162 bool bufferLookup(uint idx, cv::Mat *out);
163 cv::Mat getFeatureVector(cv::Mat totalVector, int position);
164 void sendBuffer(cv::Mat bufferMat, std::vector<uint> calculatedIdx);
165 void readBuffer(QMap<QString,QVariant> buffer);
166 cv::Mat stringToBufferMat(QString string);
167 QStringList collect_nns(QString path);
168 void displayErrorMessage(QString message);
169 //
170
171 cv::Mat m_bufferMat = cv::Mat();
172 std::vector<uint> m_bufferUsedIdx;
173 Reader *m_reader = nullptr;
174 signalObject *m_signalObject = nullptr;
175 // parameters
176 int m_frameReduction = -1;
177 const QRegularExpression m_nnNameFormat = QRegularExpression("^(ImageEmbedding)\\w+.onnx$");
178 QString m_nnFileName = "ImageEmbedding_NAME_DIMENSION_WIDTHxHEIGHT.onnx";
179 // widgets
180 QWidget *m_settingsWidget = nullptr;
181 QSpinBox *m_frameReductionInput = nullptr;
182 QComboBox *m_nnNameInput = nullptr;
183
184 NN::NeuralNetPtr m_neuralNet = nullptr;
185
186 void createSettingsWidget(QWidget *parent);
187};
188
189#endif // VISUALSIMILARITY_H
Factory class for creating NeuralNet instances.
The IAlgorithm interface is used to include plugin implementations for different sampling algorithms....
Definition ialgorithm.h:35
The LogFileParent class logs progress as well as information about a process (e.g....
Definition LogFileParent.h:30
The Progressable interface is used to by multithreaded actions such as sampling or exporting to repor...
Definition progressable.h:18
The Reader interface defines functions which are used for reading and parsing the import.
Definition reader.h:23
Definition visualSimilarity.h:92
QMap< QString, QVariant > generateSettings(Progressable *receiver, bool useCuda, volatile bool *stopped) override
generateSettings tries to generate the best settings for the current input
Definition visualSimilarity.cpp:390
QWidget * getSettingsWidget(QWidget *parent) override
returns a widget to change parameters of this plugin.
Definition visualSimilarity.cpp:18
QMap< QString, QVariant > getSettings() override
getter for plugin's settings
Definition visualSimilarity.cpp:401
std::vector< uint > sampleImages(const std::vector< unsigned int > &imageList, Progressable *receiver, volatile bool *stopped, bool useCuda, LogFileParent *logFile) override
sampleImages Create an keyframe list with indices of the keyframes. The algorithm reports progress to...
Definition visualSimilarity.cpp:28
void initialize(Reader *reader, QMap< QString, QVariant > buffer, signalObject *sigObj) override
initialize is called after new images have been loaded. the plugin parameters can be selected based o...
Definition visualSimilarity.cpp:354
QString getName() const override
getName Returns the plugin name
Definition visualSimilarity.cpp:349
void setSettings(QMap< QString, QVariant > settings) override
setter for plugin's settings
Definition visualSimilarity.cpp:369
Definition signalobject.h:10
std::shared_ptr< NeuralNet > NeuralNetPtr
Smart pointer type for managing NeuralNet instances.
Definition NeuralNet.h:95