digiKam
Loading...
Searching...
No Matches
dnnbasedetectormodel.h
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of digiKam
4 * https://www.digikam.org
5 *
6 * Date : 2023-09-02
7 * Description : Base class to perform low-level neural network inference
8 * for object detection and object classification
9 *
10 * SPDX-FileCopyrightText: 2023 by Quoc Hung TRAN <quochungtran1999 at gmail dot com>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16#pragma once
17
18// C++ includes
19
20#include <vector>
21
22// Qt includes
23
24#include <QHash>
25#include <QVector>
26#include <QString>
27#include <QRect>
28#include <QMutex>
29
30// Local includes
31
32#include "digikam_opencv.h"
33#include "digikam_export.h"
34#include "dnnmodelbase.h"
35
36namespace Digikam
37{
38
39class DIGIKAM_GUI_EXPORT DNNBaseDetectorModel
40{
41
42public:
43
44 explicit DNNBaseDetectorModel();
45 explicit DNNBaseDetectorModel(float scale, const cv::Scalar& val, const cv::Size& inputImgSize);
46 virtual ~DNNBaseDetectorModel() = default;
47
48 QList<QString> loadDetectionClasses();
49
50 std::vector<cv::Mat> preprocess(const cv::Mat& inputImage);
51 std::vector<cv::Mat> preprocess(const std::vector<cv::Mat>& inputBatchImages);
52
53 QList<QHash<QString, QVector<QRect> > > postprocess(const std::vector<cv::Mat>& inputBatchImages,
54 const std::vector<cv::Mat>& outs) const;
55
56 virtual QHash<QString, QVector<QRect> > postprocess(const cv::Mat& inputImage,
57 const cv::Mat& out) const = 0;
58
59 std::vector<cv::String> getOutputsNames() const;
60
65 virtual QHash<QString, QVector<QRect> > detectObjects(const cv::Mat& inputImage);
66
70 virtual QList<QHash<QString, QVector<QRect> > > detectObjects(const std::vector<cv::Mat>& inputBatchImages);
71
75 virtual QList<QString> getPredefinedClasses() const;
76
81 QList<QString> generateObjects(const cv::Mat& inputImage);
82
87 QList<QList<QString> > generateObjects(const std::vector<cv::Mat>& inputImage);
88
92 cv::Size getinputImageSize() const;
93
94public:
95
96 double showInferenceTime();
97
98public:
99
101 static float nmsThreshold;
102 static float scoreThreshold;
103
104protected:
105
106 // TODO: Set these from the DNNModel.
107
108 float scaleFactor = 1.0F;
111 QList<QString> predefinedClasses;
112
113 DNNModelBase* model = nullptr;
114
115protected:
116
117 virtual bool loadModels() = 0;
118
119private:
120
121 // Disable
123 DNNBaseDetectorModel& operator=(const DNNBaseDetectorModel&) = delete;
124};
125
126} // namespace Digikam
Definition dnnbasedetectormodel.h:40
static float scoreThreshold
Threshold for class detection score.
Definition dnnbasedetectormodel.h:102
cv::Size inputImageSize
Definition dnnbasedetectormodel.h:110
static int uiConfidenceThreshold
Threshold for bbox detection. It can be init and changed in the GUI.
Definition dnnbasedetectormodel.h:100
virtual ~DNNBaseDetectorModel()=default
virtual QHash< QString, QVector< QRect > > detectObjects(const cv::Mat &inputImage)
cv::Scalar meanValToSubtract
Definition dnnbasedetectormodel.h:109
virtual QHash< QString, QVector< QRect > > postprocess(const cv::Mat &inputImage, const cv::Mat &out) const =0
static float nmsThreshold
Threshold for nms suppression.
Definition dnnbasedetectormodel.h:101
QList< QString > predefinedClasses
Definition dnnbasedetectormodel.h:111
Definition dnnmodelbase.h:35
Definition datefolderview.cpp:34