-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker.cpp
More file actions
121 lines (94 loc) · 3.29 KB
/
worker.cpp
File metadata and controls
121 lines (94 loc) · 3.29 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright 2013 Fabien Pierre-Nicolas.
- Primarily authored by Fabien Pierre-Nicolas
This file is part of simple-qt-thread-example, a simple example to demonstrate how to use threads.
This example is explained on http://fabienpn.wordpress.com/qt-thread-simple-and-stable-with-sources/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This progra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "worker.h"
#include <QTimer>
#include <QEventLoop>
#include <QThread>
#include <QDebug>
#include <iostream>
#include "./algorithm/geomatch.h"
Worker::Worker(QObject *parent) :
QObject(parent)
{
_working =false;
_abort = false;
result_num_ = 0;
picking_pos_delta_ = cv::Point(0,0);
this->search_canny_low_ = 50;
this->search_canny_high_ = 100;
}
void Worker::requestWork()
{
mutex.lock();
_working = true;
_abort = false;
qDebug()<<"Request worker start in Thread "<<thread()->currentThreadId();
mutex.unlock();
emit workRequested();
}
void Worker::abort()
{
mutex.lock();
if (_working) {
_abort = true;
qDebug()<<"Request worker aborting in Thread "<<thread()->currentThreadId();
}
mutex.unlock();
}
void Worker::doWork()
{
qDebug()<<"Starting worker process in Thread "<<thread()->currentThreadId();
int i=0;
while(1) {
mutex.lock();
bool abort = _abort;
mutex.unlock();
if (abort) {
qDebug()<<"Aborting worker process in Thread "<<thread()->currentThreadId();
break;
}
mutex.lock();
cv::Mat t_img = this->template_img_;
cv::Mat s_img = this->search_img_;
int temp_canny_low = this->temp_canny_low_;
int temp_canny_high = this->temp_canny_high_;
int search_canny_low = this->search_canny_low_;
int search_canny_high = this->search_canny_high_;
mutex.unlock();
cv::Point ret_p;
double ret_ang, match_ratio;
if(geomatch::func(t_img, s_img, temp_canny_low, temp_canny_high, search_canny_low, search_canny_high, ret_p, ret_ang, match_ratio)){
//std::cout << "result angle1: " << ret_ang << std::endl;
//std::cout << "match ratio: " << match_ratio << std::endl;
result_num_ = 1;
result_pos_ = ret_p;
result_angle_ = ret_ang;
match_ratio_ = match_ratio;
}else {
result_num_ = 0;
}
//emit valueChanged(QString::number(i));
i++;
}
// Set _working to false, meaning the process can't be aborted anymore.
mutex.lock();
_working = false;
mutex.unlock();
qDebug()<<"Worker process finished in Thread "<<thread()->currentThreadId();
//Once 60 sec passed, the finished signal is sent
emit finished();
}