File indexing completed on 2025-01-19 03:57:56
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-09-03 0007 * Description : Integrated, multithread face detection / recognition 0008 * 0009 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2012-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_FACE_PIPELINE_PACKAGE_H 0017 #define DIGIKAM_FACE_PIPELINE_PACKAGE_H 0018 0019 // Qt includes 0020 0021 #include <QFlags> 0022 #include <QThread> 0023 0024 // Local includes 0025 0026 #include "identity.h" 0027 #include "digikam_debug.h" 0028 #include "facetagsiface.h" 0029 #include "dimg.h" 0030 #include "loadingdescription.h" 0031 #include "iteminfo.h" 0032 //#include "recognitiondatabase.h" 0033 0034 namespace Digikam 0035 { 0036 0037 class DetectionBenchmarker; 0038 class RecognitionBenchmarker; 0039 class DetectionWorker; 0040 class RecognitionWorker; 0041 class TrainerWorker; 0042 class DatabaseWriter; 0043 class FacePreviewLoader; 0044 class FaceItemRetriever; 0045 class ParallelPipes; 0046 class ScanStateFilter; 0047 0048 class FacePipelineFaceTagsIface : public FaceTagsIface 0049 { 0050 public: 0051 0052 enum Role 0053 { 0054 NoRole = 0, 0055 0056 /// Source 0057 GivenAsArgument = 1 << 0, 0058 ReadFromDatabase = 1 << 1, 0059 DetectedFromImage = 1 << 2, 0060 0061 /// Task 0062 ForRecognition = 1 << 10, 0063 ForConfirmation = 1 << 11, 0064 ForTraining = 1 << 12, 0065 ForEditing = 1 << 13, ///< Add, Change or remove 0066 0067 /// Executed action (task is cleared) 0068 Confirmed = 1 << 20, 0069 Trained = 1 << 21, 0070 Edited = 1 << 22 0071 }; 0072 Q_DECLARE_FLAGS(Roles, Role) 0073 0074 public: 0075 0076 FacePipelineFaceTagsIface(); 0077 explicit FacePipelineFaceTagsIface(const FaceTagsIface& face); 0078 ~FacePipelineFaceTagsIface(); 0079 0080 public: 0081 0082 Roles roles; 0083 int assignedTagId; 0084 TagRegion assignedRegion; 0085 }; 0086 0087 // ------------------------------------------------------------------------------------ 0088 0089 class FacePipelineFaceTagsIfaceList : public QList<FacePipelineFaceTagsIface> 0090 { 0091 public: 0092 0093 FacePipelineFaceTagsIfaceList(); 0094 explicit FacePipelineFaceTagsIfaceList(const QList<FaceTagsIface>& faces); 0095 ~FacePipelineFaceTagsIfaceList(); 0096 0097 FacePipelineFaceTagsIfaceList& operator=(const QList<FaceTagsIface>& faces); 0098 0099 public: 0100 0101 void setRole(FacePipelineFaceTagsIface::Roles role); 0102 void clearRole(FacePipelineFaceTagsIface::Roles role); 0103 void replaceRole(FacePipelineFaceTagsIface::Roles remove, 0104 FacePipelineFaceTagsIface::Roles add); 0105 0106 QList<FaceTagsIface> toFaceTagsIfaceList() const; 0107 0108 FacePipelineFaceTagsIfaceList facesForRole(FacePipelineFaceTagsIface::Roles role) const; 0109 }; 0110 0111 // ------------------------------------------------------------------------------------ 0112 0113 class FacePipelinePackage 0114 { 0115 public: 0116 0117 enum ProcessFlag 0118 { 0119 NotProcessed = 0, 0120 PreviewImageLoaded = 1 << 0, 0121 ProcessedByDetector = 1 << 1, 0122 ProcessedByRecognizer = 1 << 2, 0123 WrittenToDatabase = 1 << 3, 0124 ProcessedByTrainer = 1 << 4 0125 }; 0126 Q_DECLARE_FLAGS(ProcessFlags, ProcessFlag) 0127 0128 public: 0129 0130 explicit FacePipelinePackage(); 0131 ~FacePipelinePackage(); 0132 0133 public: 0134 0135 ItemInfo info; 0136 DImg image; 0137 QList<QRectF> detectedFaces; 0138 QList<Identity> recognitionResults; 0139 FacePipelineFaceTagsIfaceList databaseFaces; 0140 0141 ProcessFlags processFlags; 0142 }; 0143 0144 // ------------------------------------------------------------------------------------ 0145 0146 class Q_DECL_HIDDEN FacePipelineExtendedPackage : public FacePipelinePackage, 0147 public QSharedData 0148 { 0149 public: 0150 0151 explicit FacePipelineExtendedPackage(); 0152 ~FacePipelineExtendedPackage(); 0153 0154 bool operator==(const LoadingDescription& description) const; 0155 0156 public: 0157 0158 QString filePath; 0159 typedef QExplicitlySharedDataPointer<FacePipelineExtendedPackage> Ptr; 0160 }; 0161 0162 // ---------------------------------------------------------------------------------------- 0163 0164 class Q_DECL_HIDDEN PackageLoadingDescriptionList : public QList<FacePipelineExtendedPackage::Ptr> 0165 { 0166 public: 0167 0168 explicit PackageLoadingDescriptionList(); 0169 ~PackageLoadingDescriptionList(); 0170 0171 FacePipelineExtendedPackage::Ptr take(const LoadingDescription& description); 0172 }; 0173 0174 } // namespace Digikam 0175 0176 Q_DECLARE_METATYPE(Digikam::FacePipelinePackage) 0177 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::FacePipelineFaceTagsIface::Roles) 0178 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::FacePipelinePackage::ProcessFlags) 0179 0180 #endif // DIGIKAM_FACE_PIPELINE_PACKAGE_H