-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmanualmatch.cpp
More file actions
175 lines (149 loc) · 5.11 KB
/
manualmatch.cpp
File metadata and controls
175 lines (149 loc) · 5.11 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "manualmatch.h"
#include "ui_manualmatch.h"
#include <QImage>
#include <QPainter>
#include <QMessageBox>
QFont textfont("Calibri",50);
QColor gcolor(0,255,0);
QColor rcolor(255,0,0);
ManualMatch::ManualMatch(QWidget *parent) :
QWidget(parent),
ui(new Ui::ManualMatch)
{
ui->setupUi(this);
connect(ui->confirmButton,SIGNAL(clicked()),this,SLOT(confirmID()));
connect(ui->finishButton,SIGNAL(clicked()),this,SLOT(finish()));
connect(ui->cancelButton,SIGNAL(clicked()),this,SLOT(hide()));
connect(ui->resetButton,SIGNAL(clicked()),this,SLOT(reset()));
connect(ui->deleteButton,SIGNAL(clicked()),this,SLOT(deletepoint()));
//connect(ui->idEdit,SIGNAL(textEdited(QString)),ui->confirmButton,SLOT(setEnabled(bool)));
onMark = 0;
}
ManualMatch::~ManualMatch()
{
delete ui;
}
void ManualMatch::setImage()
{
QImage pimage_1 = QImage(leftImage.data,leftImage.cols,leftImage.rows,QImage::Format_Indexed8);
QImage pimage_2 = QImage(rightImage.data,rightImage.cols,rightImage.rows,QImage::Format_Indexed8);
QPixmap pcopy_1 = QPixmap::fromImage(pimage_1);
QPixmap pcopy_2 = QPixmap::fromImage(pimage_2);
QPainter pt_1(&pcopy_1);
QPainter pt_2(&pcopy_2);
pt_1.setFont(textfont);
pt_2.setFont(textfont);
for(size_t i = 0;i < dotInOrder.size();i++){
pt_1.setPen(gcolor);
pt_2.setPen(gcolor);
drawCross(pt_1, dotInOrder[i][0].x ,dotInOrder[i][0].y);
drawCross(pt_2, dotInOrder[i][1].x, dotInOrder[i][1].y);
int ID;
if (refinedCorr.size()>i){//根据refinedCorr中的数据(如果有)显示i点ID
for (size_t r = 0; r < refinedCorr.size(); r++){
if (i == refinedCorr[r].y)
ID = refinedCorr[r].x;
}
pt_1.drawText(dotInOrder[i][0].x,dotInOrder[i][0].y,QString::number(ID));
pt_2.drawText(dotInOrder[i][1].x,dotInOrder[i][1].y,QString::number(ID));
}
else{//若refinedPoint还未被赋予空间,根据correspond中的数据显示i点ID
bool idexist = false;//表示ID点的对应点存在,只关系到ID的显示状态
for (size_t c = 0; c < correspond.size(); c++){
if (i == correspond[c].y){
ID = correspond[c].x;
idexist = true;
}
}
if (idexist){
pt_1.drawText(dotInOrder[i][0].x,dotInOrder[i][0].y,QString::number(ID));
pt_2.drawText(dotInOrder[i][1].x,dotInOrder[i][1].y,QString::number(ID));
}
else{
pt_1.drawText(dotInOrder[i][0].x,dotInOrder[i][0].y,"?");
pt_2.drawText(dotInOrder[i][1].x,dotInOrder[i][1].y,"?");
}
}
}
///用红色方框标记当前准备赋予编号的点
pt_1.setPen(rcolor);
pt_2.setPen(rcolor);
pt_1.drawRect(dotInOrder[onMark][0].x-15,dotInOrder[onMark][0].y-15,30,30);
pt_2.drawRect(dotInOrder[onMark][1].x-15,dotInOrder[onMark][1].y-15,30,30);
ui->leftImage->setPixmap(pcopy_1);
ui->rightImage->setPixmap(pcopy_2);
int ID;
if (!refinedCorr.empty()){
if (refinedCorr[onMark].x >= 0){//如果onMark点已经被标记过,则在idEdit中显示ID值
ID = refinedCorr[onMark].x;
ui->idEdit->setText(QString::number(ID));
}
else
ui->idEdit->clear();
}
}
void ManualMatch::confirmID()
{
if (refinedCorr.size() == 0)
refinedCorr.resize(dotInOrder.size(),cv::Point2i(-1,-1));
int id = ui->idEdit->text().toInt();
cv::Point2i corr;
corr.x = id;
corr.y = onMark;
refinedCorr.at(onMark) = corr;
if (onMark == dotInOrder.size() - 1)
onMark = 0;
else
onMark++;
ui->current->setText(QString::number(onMark));
setImage();//根据新的信息重绘图像
}
void ManualMatch::deletepoint()
{
if (onMark < dotInOrder.size() - 1){
dotInOrder.erase(dotInOrder.begin() + onMark);
correspond.erase(correspond.begin() + onMark);
//refinedCorr.erase(refinedCorr.begin() + onMark);
}
else{
dotInOrder.erase(dotInOrder.end() - 1);
correspond.erase(correspond.end() - 1);
//refinedCorr.erase(refinedCorr.end());
}
setImage();
}
void ManualMatch::finish()
{
if (refinedCorr.size() == 0){
for (size_t i = 0;i < correspond.size(); i++){
refinedCorr.push_back(correspond[i]);
}
}
else{
for (size_t i = 0;i < refinedCorr.size(); i++){
if (refinedCorr[i].x < 0)
QMessageBox::warning(NULL,"Manual Match",tr("Point ") + QString::number(i) + tr(" hasn't been marked."));
}
}
this->hide();
emit outputdata();
}
void ManualMatch::reset()
{
refinedCorr.clear();
onMark = 0;
setImage();
}
void ManualMatch::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Enter)
confirmID();
else if (e->key() == Qt::Key_Delete)
deletepoint();
}
void ManualMatch::drawCross(QPainter &p, int x, int y)
{
int len = 25;
p.drawLine(x - len, y, x + len, y);
p.drawLine(x, y - len, x, y + len);
}