forked from stupel/Preprocessing
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gaborfiltermultithread.cpp
executable file
·67 lines (54 loc) · 2.91 KB
/
gaborfiltermultithread.cpp
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
#include "gaborfiltermultithread.h"
GaborFilterMultiThread::GaborFilterMultiThread(QObject *parent) : QObject(parent)
{
}
void GaborFilterMultiThread::setParams(const cv::Mat &imgInput, const GABOR_PARAMS &gaborParams)
{
this->imgInput = imgInput;
this->gabor = gaborParams;
}
void GaborFilterMultiThread::enhance()
{
this->threadsFinished = 0; // na zaciatku paralelneho filtrovania nastavujem pocet ukoncenych vlakien na 0
this->imgEnhanced = cv::Mat(this->imgInput.rows,this->imgInput.cols, CV_32F, cv::Scalar::all(255));
QVector<GaborThread*> gaborThreads; // vlakna na paralelne filtrovanie
threads.clear(); // vymazu sa predchadzajuce vlakna
for(int i = 0; i < *this->gabor.threadNum; i++){
int threadBlock_Width = this->imgInput.cols - this->gabor.blockSize;
int threadBlock_Height = (this->imgInput.rows - this->gabor.blockSize) / *this->gabor.threadNum;
int topLeftCorner_X = qFloor(this->gabor.blockSize / 2);
int topLeftCorner_Y = qFloor(this->gabor.blockSize / 2) + i * threadBlock_Height ; // pozor!!!
threads.push_back(new QThread());
gaborThreads.push_back(new GaborThread(this->imgInput, this->gabor, cv::Rect(topLeftCorner_X, topLeftCorner_Y, threadBlock_Width, threadBlock_Height), this->imgEnhanced));
gaborThreads.last()->moveToThread(threads.last()); // pridanie do samostatneho vlakna
connect(threads.last(), SIGNAL(finished()), gaborThreads.last(), SLOT(deleteLater()));
connect(threads.last(), SIGNAL(finished()), threads.last(), SLOT(deleteLater()));
connect(gaborThreads.last(), SIGNAL(enhanceFragmentSignal()), gaborThreads.last(), SLOT(enhanceFragmentSlot()));
connect(gaborThreads.last(), SIGNAL(enhancementDoneSignal()), this, SLOT(oneGaborThreadFinished()));
connect(gaborThreads.last(), SIGNAL(enhancementDoneSignal()), gaborThreads.last(), SLOT(enhancementDoneSlot()));
threads.last()->start(); // vlakno vstupi do event loop-u
// paralelne filtrovanie odtlacku
// funguje to tak, ze jednotlive vlakna si zdielaju 1 odtlacok a kazde filtruje len urcitu cast
emit gaborThreads.last()->enhanceFragmentSignal(); // vyslanie signalu na zacatie filtrovania
}
}
void GaborFilterMultiThread::oneGaborThreadFinished()
{
// ak vsetky vlakna ukoncili svoju cinnost
if(++this->threadsFinished == *this->gabor.threadNum){
// obrazok sa znormalizuje
cv::normalize(this->imgEnhanced, this->imgEnhanced, 0.0, 255.0, cv::NORM_MINMAX);
// konverzia do grayscale formatu
this->imgEnhanced.convertTo(this->imgEnhanced, CV_8UC1);
// ukoncenie vlakien
foreach (QThread* t, this->threads) {
t->quit();
//t->wait();
}
emit gaborThreadsFinished();
}
}
cv::Mat GaborFilterMultiThread::getImgEnhanced() const
{
return imgEnhanced;
}