digiKam
dnnfacedetectorbase.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam
4  *
5  * Date : 2019-08-08
6  * Description : Base class to perform low-level neural network inference
7  * for face detection
8  *
9  * Copyright (C) 2019 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
10  * Copyright (C) 2020-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_FACESENGINE_DNN_FACE_DETECTOR_BASE_H
26 #define DIGIKAM_FACESENGINE_DNN_FACE_DETECTOR_BASE_H
27 
28 // C++ includes
29 
30 #include <vector>
31 
32 // Qt includes
33 
34 #include <QMutex>
35 
36 // Local includes
37 
38 #include "digikam_opencv.h"
39 
40 namespace Digikam
41 {
42 
44 {
45 
46 public:
47 
48  explicit DNNFaceDetectorBase();
49  explicit DNNFaceDetectorBase(float scale, const cv::Scalar& val, const cv::Size& inputImgSize);
50  virtual ~DNNFaceDetectorBase();
51 
52  virtual void detectFaces(const cv::Mat& inputImage,
53  const cv::Size& paddedSize,
54  std::vector<cv::Rect>& detectedBboxes) = 0;
55 
56  cv::Size nnInputSizeRequired() const;
57 
58 protected:
59 
60  void selectBbox(const cv::Size& paddedSize,
61  float confidence,
62  int left,
63  int right,
64  int top,
65  int bottom,
66  std::vector<float>& goodConfidences, std::vector<cv::Rect>& goodBoxes,
67  std::vector<float>& doubtConfidences, std::vector<cv::Rect>& doubtBoxes) const;
68 
69  void correctBbox(cv::Rect& bbox,
70  const cv::Size& paddedSize) const;
71 
72 public:
73 
74  static float confidenceThreshold;
75  static float nmsThreshold;
76 
77 protected:
78 
79  float scaleFactor;
80  cv::Scalar meanValToSubtract;
81  cv::Size inputImageSize;
82 
83  cv::dnn::Net net;
84 
85  QMutex mutex;
86 
87 private:
88 
89  // Disable
91  DNNFaceDetectorBase& operator=(const DNNFaceDetectorBase&) = delete;
92 };
93 
94 } // namespace Digikam
95 
96 #endif // DIGIKAM_FACESENGINE_DNN_FACE_DETECTOR_BASE_H
Definition: dnnfacedetectorbase.h:44
cv::dnn::Net net
Definition: dnnfacedetectorbase.h:83
void correctBbox(cv::Rect &bbox, const cv::Size &paddedSize) const
Definition: dnnfacedetectorbase.cpp:128
cv::Size nnInputSizeRequired() const
Definition: dnnfacedetectorbase.cpp:63
static float confidenceThreshold
Threshold for bbox detection. It can be init and changed in the GUI.
Definition: dnnfacedetectorbase.h:74
float scaleFactor
Definition: dnnfacedetectorbase.h:79
DNNFaceDetectorBase()
Definition: dnnfacedetectorbase.cpp:45
virtual ~DNNFaceDetectorBase()
Definition: dnnfacedetectorbase.cpp:59
cv::Size inputImageSize
Definition: dnnfacedetectorbase.h:81
virtual void detectFaces(const cv::Mat &inputImage, const cv::Size &paddedSize, std::vector< cv::Rect > &detectedBboxes)=0
cv::Scalar meanValToSubtract
Definition: dnnfacedetectorbase.h:80
static float nmsThreshold
Threshold for nms suppression.
Definition: dnnfacedetectorbase.h:75
void selectBbox(const cv::Size &paddedSize, float confidence, int left, int right, int top, int bottom, std::vector< float > &goodConfidences, std::vector< cv::Rect > &goodBoxes, std::vector< float > &doubtConfidences, std::vector< cv::Rect > &doubtBoxes) const
Definition: dnnfacedetectorbase.cpp:70
QMutex mutex
Definition: dnnfacedetectorbase.h:85
Definition: datefolderview.cpp:43