1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 28/08/2021
 * Description : Image Quality Parser - Thread to run detectors
 *
 * SPDX-FileCopyrightText: 2021-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
 * SPDX-FileCopyrightText: 2021-2022 by Phuoc Khanh Le <phuockhanhnk94 at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#include "imagequalitythread.h"

namespace Digikam
{

ImageQualityThread::ImageQualityThread(QObject* const parent,
                                       AbstractDetector* const detector,
                                       const cv::Mat& image,
                                       ImageQualityCalculator* const calculator,
                                       float weight_quality)
    : QThread     (parent),
      m_detector  (detector),
      m_calculator(calculator),
      m_image     (image),
      m_weight    (weight_quality)
{
}

void ImageQualityThread::run()
{
    float damageLevel = m_detector->detect(m_image);
    m_calculator->addDetectionResult(QString(), damageLevel, m_weight);
}

//--------------------------------------------------------------------------

ImageQualityThreadPool::ImageQualityThreadPool(QObject* const parent,
                                               ImageQualityCalculator* const calculator)
    : QObject     (parent),
      m_calculator(calculator)
{
}

ImageQualityThreadPool::~ImageQualityThreadPool()
{
    end();
/*
    for (auto& thread : std::as_const(m_threads))
    {
        delete thread;
    }
*/
}


void ImageQualityThreadPool::addDetector(const cv::Mat& image,
                                         float weight_quality,
                                         AbstractDetector* const detector)
{
    ImageQualityThread* const thread = new ImageQualityThread(this,<--- Variable 'thread' can be declared as pointer to const
                                                              detector,
                                                              image,
                                                              m_calculator,
                                                              weight_quality);
/*
    connect(thread, &QThread::finished,
            thread, &QObject::deleteLater);
*/
    m_threads.push_back(thread);
}

void ImageQualityThreadPool::start()
{
    for (const auto& thread : std::as_const(m_threads))
    {
        thread->start();
    }
}

void ImageQualityThreadPool::end()
{
    for (auto& thread : std::as_const(m_threads))
    {
        thread->quit();
        thread->wait();
    }
}

} // namespace Digikam

#include "moc_imagequalitythread.cpp"