File indexing completed on 2025-03-09 03:54:58
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam 0004 * 0005 * Date : 2019-07-22 0006 * Description : Class to perform faces detection using OpenCV DNN module 0007 * 0008 * SPDX-FileCopyrightText: 2019 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com> 0009 * SPDX-FileCopyrightText: 2020-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_FACESENGINE_OPENCV_DNN_FACE_DETECTOR_H 0016 #define DIGIKAM_FACESENGINE_OPENCV_DNN_FACE_DETECTOR_H 0017 0018 // Qt includes 0019 0020 #include <QImage> 0021 #include <QList> 0022 #include <QRect> 0023 0024 // Local includes 0025 0026 #include "digikam_opencv.h" 0027 #include "dimg.h" 0028 #include "dnnfacedetectorbase.h" 0029 0030 namespace Digikam 0031 { 0032 0033 enum DetectorNNModel 0034 { 0035 SSDMOBILENET = 0, ///< SSD MobileNet neural network inference. 0036 YOLO ///< YOLO neural network inference. 0037 }; 0038 0039 class DIGIKAM_EXPORT OpenCVDNNFaceDetector 0040 { 0041 0042 public: 0043 0044 explicit OpenCVDNNFaceDetector(DetectorNNModel model = DetectorNNModel::SSDMOBILENET); 0045 ~OpenCVDNNFaceDetector(); 0046 0047 cv::Mat prepareForDetection(const DImg& inputImage, cv::Size& paddedSize) const; 0048 cv::Mat prepareForDetection(const QImage& inputImage, cv::Size& paddedSize) const; 0049 cv::Mat prepareForDetection(const QString& inputImagePath, cv::Size& paddedSize) const; 0050 0051 QList<QRect> detectFaces(const cv::Mat& inputImage, const cv::Size& paddedSize); 0052 std::vector<cv::Rect> cvDetectFaces(const cv::Mat& inputImage, const cv::Size& paddedSize); 0053 0054 /** 0055 * Returns the image size (one dimension) 0056 * recommended for face detection. If the image is considerably larger, it will be rescaled automatically. 0057 */ 0058 static int recommendedImageSizeForDetection(); 0059 0060 private: 0061 0062 cv::Mat prepareForDetection(cv::Mat& cvImage, cv::Size& paddedSize) const; 0063 0064 private: 0065 0066 // Disable 0067 OpenCVDNNFaceDetector(const OpenCVDNNFaceDetector&) = delete; 0068 OpenCVDNNFaceDetector& operator=(const OpenCVDNNFaceDetector&) = delete; 0069 0070 private: 0071 0072 DetectorNNModel m_modelType; 0073 DNNFaceDetectorBase* m_inferenceEngine; 0074 }; 0075 0076 } // namespace Digikam 0077 0078 #endif // DIGIKAM_FACESENGINE_OPENCV_DNN_FACE_DETECTOR_H