File indexing completed on 2025-01-19 03:57:55
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 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "faceitemretriever.h" 0016 0017 namespace Digikam 0018 { 0019 0020 FaceItemRetriever::FaceItemRetriever(FacePipeline::Private* const d) 0021 : catcher(new ThumbnailImageCatcher(d->createThumbnailLoadThread(), d)) 0022 { 0023 } 0024 0025 FaceItemRetriever::~FaceItemRetriever() 0026 { 0027 } 0028 0029 void FaceItemRetriever::cancel() 0030 { 0031 catcher->cancel(); 0032 } 0033 0034 QList<QImage*> FaceItemRetriever::getDetails(const DImg& src, const QList<QRectF>& rects) const 0035 { 0036 QList<QImage*> images; 0037 0038 Q_FOREACH (const QRectF& rect, rects) 0039 { 0040 QImage* const croppedFace = new QImage(); 0041 (*croppedFace) = src.copyQImage(rect); 0042 0043 images << croppedFace; 0044 } 0045 0046 return images; 0047 } 0048 0049 QList<QImage*> FaceItemRetriever::getDetails(const DImg& src, const QList<FaceTagsIface>& faces) const 0050 { 0051 QList<QImage*> images; 0052 0053 Q_FOREACH (const FaceTagsIface& face, faces) 0054 { 0055 QRect rect = TagRegion::mapFromOriginalSize(src, face.region().toRect()); 0056 0057 QImage* const croppedFace = new QImage(); 0058 (*croppedFace) = src.copyQImage(rect); 0059 0060 images << croppedFace; 0061 } 0062 0063 return images; 0064 } 0065 0066 QList<QImage*> FaceItemRetriever::getThumbnails(const QString& filePath, const QList<FaceTagsIface>& faces) const 0067 { 0068 Q_UNUSED(filePath) 0069 catcher->setActive(true); 0070 0071 Q_FOREACH (const FaceTagsIface& face, faces) 0072 { 0073 QRect rect = face.region().toRect(); 0074 catcher->thread()->find(ItemInfo::thumbnailIdentifier(face.imageId()), rect); 0075 catcher->enqueue(); 0076 } 0077 0078 QList<QImage> images = catcher->waitForThumbnails(); 0079 0080 QList<QImage*> croppedFaces; 0081 0082 for (int i = 0 ; i < images.size() ; ++i) 0083 { 0084 QImage* const croppedFace = new QImage(); 0085 (*croppedFace) = images[i].copy(); 0086 0087 croppedFaces << croppedFace; 0088 } 0089 0090 catcher->setActive(false); 0091 0092 return croppedFaces; 0093 } 0094 0095 } // namespace Digikam