File indexing completed on 2025-03-09 03:54:59
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam 0004 * 0005 * Date : 2010-09-02 0006 * Description : A convenience class for a standalone face detector 0007 * 0008 * SPDX-FileCopyrightText: 2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0009 * SPDX-FileCopyrightText: 2010 by Aditya Bhatt <adityabhatt1991 at gmail dot com> 0010 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_FACESENGINE_FACEDETECTOR_H 0017 #define DIGIKAM_FACESENGINE_FACEDETECTOR_H 0018 0019 // Qt includes 0020 0021 #include <QExplicitlySharedDataPointer> 0022 #include <QImage> 0023 #include <QVariant> 0024 0025 // Local includes 0026 0027 #include "digikam_export.h" 0028 #include "dimg.h" 0029 0030 namespace Digikam 0031 { 0032 0033 class DIGIKAM_EXPORT FaceDetector 0034 { 0035 0036 public: 0037 0038 /** 0039 * Provides face detection, that means the process of selecting 0040 * those regions of a full image which contain face. 0041 * 0042 * This class provides shallow copying 0043 * The class is fully reentrant (a single object and its copies are not thread-safe). 0044 * Deferred creation is guaranteed, that means creation of a FaceDetector 0045 * object is cheap, the expensive creation of the detection backend 0046 * is performed when detectFaces is called for the first time. 0047 */ 0048 FaceDetector(); 0049 FaceDetector(const FaceDetector& other); 0050 ~FaceDetector(); 0051 0052 QString backendIdentifier() const; 0053 0054 FaceDetector& operator=(const FaceDetector& other); 0055 0056 /** 0057 * Scan an image for faces. Return a list with regions possibly 0058 * containing faces. 0059 * If the image has been downscaled anywhere in the process, 0060 * provide the original size of the image as this may be of importance in the detection process. 0061 * 0062 * Found faces are returned in relative coordinates. 0063 */ 0064 QList<QRectF> detectFaces(const QImage& image, const QSize& originalSize = QSize()); 0065 0066 /** 0067 * Scan an image for faces. Return a list with regions possibly 0068 * containing faces. 0069 * If the image has been downscaled anywhere in the process, 0070 * provide the original size of the image as this may be of importance in the detection process. 0071 * 0072 * Found faces are returned in relative coordinates. 0073 */ 0074 QList<QRectF> detectFaces(const DImg& image, const QSize& originalSize = QSize()); 0075 0076 QList<QRectF> detectFaces(const QString& imagePath); 0077 0078 /** 0079 * Tunes backend parameters. 0080 * Available parameters: 0081 * 0082 * "speed" vs. "accuracy", 0..1, float 0083 * "sensitivity" vs. "specificity", 0..1, float. 0084 * 0085 * For both pairs: a = 1-b, you can set either. 0086 * The first pair changes the ROC curve in a trade for computing time. 0087 * The second pair moves on a given ROC curve towards more false positives, or more missed faces. 0088 */ 0089 void setParameter(const QString& parameter, const QVariant& value); 0090 void setParameters(const QVariantMap& parameters); 0091 QVariantMap parameters() const; 0092 0093 /** 0094 * Returns the recommended size if you want to scale images for detection. 0095 * Larger images can be passed, but may be downscaled. 0096 */ 0097 int recommendedImageSize(const QSize& availableSize = QSize()) const; 0098 0099 static QRectF toRelativeRect(const QRect& absoluteRect, const QSize& size); 0100 static QRect toAbsoluteRect(const QRectF& relativeRect, const QSize& size); 0101 static QList<QRectF> toRelativeRects(const QList<QRect>& absoluteRects, const QSize& size); 0102 static QList<QRect> toAbsoluteRects(const QList<QRectF>& relativeRects, const QSize& size); 0103 0104 private: 0105 0106 class Private; 0107 QExplicitlySharedDataPointer<Private> d; 0108 }; 0109 0110 } // namespace Digikam 0111 0112 #endif // DIGIKAM_FACESENGINE_FACEDETECTOR_H