13#include <QCoreApplication>
17#include <QRegularExpression>
18#include <QSignalBlocker>
24#include <QtConcurrent>
29#include <opencv2/core.hpp>
30#include <opencv2/opencv.hpp>
31#include <opencv2/dnn.hpp>
32#include <opencv2/imgcodecs.hpp>
33#include <opencv2/imgproc.hpp>
34#include <opencv2/tracking/tracking_by_matching.hpp>
39#include "iselection.h"
42#define RESSOURCE_PATH "/plugins/resources/neural_network_models/"
43#define MEM_THRESEHOLD 0.5f
45#define NN_STD {0.229, 0.224, 0.225}
46#define NN_MEAN {0.485, 0.456, 0.406}
49#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;"
50#define UI_FRAMEREDUCTION_NAME QObject::tr("Select one frame every K frames")
51#define UI_FRAMEREDUCTION_DESC QObject::tr("Reduces the amount of selected frames by the factor K.")
52#define UI_NNNAME_NAME QObject::tr("Selected Neural Network")
53#define UI_NNNAME_DESC QObject::tr("The drop-down shows all files in plugins/resources/neural_network_models matching ImageEmbedding*.onnx")
56#define FRAMEREDUCTION_JSON_NAME "K"
57#define NNNAME_JSON_NAME "NN-Name"
60#define LF_TIMER_KEYFRAMES "keyframeSelection"
61#define LF_TTHRESHOLD "tDistThreshold"
62#define LF_RESULT_INFO_TAG "result_info"
63#define LF_COMPUTE_INFO_TAG "compute_info"
64#define LF_SELECTION_INFO_TAG "selection_info"
65#define LF_TIMER_NN "NN feeding timer"
66#define LF_TIMER_KMEANS "kMeans timer"
67#define LF_TIMER_BUFFER "safe buffer timer"
83 Q_PLUGIN_METADATA(IID
"iVS3D.IBase")
92 QString
getName()
const override;
93 QMap<QString, QVariant>
getSettings()
const override;
95 const QMap<QString, QVariant>& settings)
override;
102 volatile bool& cancelFlag)
override;
105 void syncSettingsWidget(
int frameReduction,
107 QStringList availableNns,
112 void slot_selectedNNChanged(
const QString& nnName);
113 void slot_frameReductionChanged(
int value);
116 std::unique_ptr<QWidget> createSettingsWidget();
117 PLUG::SelectionResult sampleImages(
const std::vector<uint>& imageList,
118 std::shared_ptr<LogFileParent> logFile,
119 volatile bool& cancelFlag);
120 bool bufferLookup(uint idx, cv::Mat* out)
const;
121 cv::Mat getFeatureVector(
const cv::Mat& totalVector,
int position)
const;
122 QStringList collectNns(
const QString& path)
const;
125 cv::Mat m_bufferMat = cv::Mat();
126 std::vector<uint> m_bufferUsedIdx;
127 Reader* m_reader =
nullptr;
128 bool m_useCuda =
false;
131 int m_frameReduction = 30;
132 const QRegularExpression m_nnNameFormat = QRegularExpression(
"^(ImageEmbedding)\\w+.onnx$");
133 QString m_nnFileName =
"ImageEmbedding_NAME_DIMENSION_WIDTHxHEIGHT.onnx";
136 QSpinBox* m_frameReductionInput =
nullptr;
137 QComboBox* m_nnNameInput =
nullptr;
140 int m_featureDims = -1;
Factory class for creating NeuralNet instances.
Represents an error that occurred in the neural network module and contains the error type and messag...
Definition NeuralError.h:48
Represents an error with a code and a message. The message is intended for display to the user.
Definition ierror.h:28
The IBase interface provides a base class for all plugin interfaces in iVS3D. It inherits from QObjec...
Definition ibase.h:102
Interface for keyframe/image-selection plugins in iVS3D.
Definition iselection.h:53
The Reader interface defines functions which are used for reading and parsing the import.
Definition reader.h:23
Definition visualSimilarity.h:81
PLUG::SettingsWidgetResult getSettingsWidget() override
getSettingsWidget creates and returns a settings QWidget for this plugin.
Definition visualSimilarity.cpp:34
QMap< QString, QVariant > getSettings() const override
getSettings retrieves the current settings of the plugin as a map of key-value pairs....
Definition visualSimilarity.cpp:51
void onCudaChanged(bool enabled) override
onCudaChanged is called when the CUDA usage setting is changed in iVS3D.
Definition visualSimilarity.cpp:120
PLUG::ApplySettingsResult applySettings(const QMap< QString, QVariant > &settings) override
applySettings applies the provided settings to the plugin. This method is used to restore plugin conf...
Definition visualSimilarity.cpp:59
PLUG::SelectionResult selectImages(const PLUG::SelectionData &data, volatile bool &cancelFlag) override
Selects images based on the provided selection data.
Definition visualSimilarity.cpp:130
QString getName() const override
getName returns the name of the plugin which will be displayed in the iVS3D interface.
Definition visualSimilarity.cpp:46
PLUG::InputLoadedResult onInputLoaded(const PLUG::InputData &input) override
onInputLoaded is called when a new input video or image set is loaded.
Definition visualSimilarity.cpp:93
std::shared_ptr< NeuralNet > NeuralNetPtr
Smart pointer type for managing NeuralNet instances.
Definition NeuralNet.h:121
tl::expected< void, Error > InputLoadedResult
Type alias for the result of handling an input loaded event, which can be either a successful void re...
Definition ibase.h:58
tl::expected< void, Error > ApplySettingsResult
Type alias for the result of applying settings to a plugin, which can be either a successful void res...
Definition ibase.h:51
tl::expected< std::unique_ptr< QWidget >, Error > SettingsWidgetResult
Type alias for the result of a settings widget creation operation, which can be either a successful u...
Definition ibase.h:44
Data available for image selection in ISelection plugins.
Definition iselection.h:31