-
Notifications
You must be signed in to change notification settings - Fork 1
/
beginningpanel.cpp
127 lines (109 loc) · 4.29 KB
/
beginningpanel.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
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
#include "beginningpanel.h"
#include "ui_beginningpanel.h"
#include "ui_mainwindow.h"
#include "mainwindow.h"
#include <QFileDialog>
#include <QtConcurrent/QtConcurrent>
#include <opencv2/imgcodecs/imgcodecs.hpp>
using namespace std;
using namespace cv;
BeginningPanel::BeginningPanel(MainWindow *main, QWidget *parent) :
TreeSubFrame(main, parent),
ui(new Ui::BeginningPanel)
{
ui->setupUi(this);
this->set_main_on_children();
this->main->get_main_video()->set_following(this->ui->frame);
this->load_image_filename("/afs/uz.sns.it/user/subotto/subtracker/data/ref2018.jpeg", "image");
this->load_image_filename("/afs/uz.sns.it/user/subotto/subtracker/data/ref_mask2018.png", "mask");
}
BeginningPanel::~BeginningPanel()
{
delete ui;
}
void BeginningPanel::add_future_watcher(const QFuture< tuple< Mat, string, string > > &future) {
auto watcher = new QFutureWatcher< tuple< Mat, string, string > >(this);
bool res;
res = connect(watcher, SIGNAL(finished()), this, SLOT(handle_future()));
assert(res);
watcher->setFuture(future);
this->watchers.push_back(watcher);
}
bool BeginningPanel::handle_one_future(QFutureWatcher< tuple<Mat, string, string> > *future) {
if (future->isFinished()) {
auto image = get<0>(future->result());
auto filename = get<1>(future->result());
auto variant = get<2>(future->result());
assert(variant == "image" || variant == "mask");
if (variant == "image") {
this->main->get_settings().ref_image = image;
this->main->get_settings().ref_image_filename = filename;
auto cmds = this->main->edit_commands();
cmds.second->new_ref = true;
} else {
this->main->get_settings().ref_mask = image;
this->main->get_settings().ref_mask_filename = filename;
auto cmds = this->main->edit_commands();
cmds.second->new_mask = true;
}
this->main->settings_modified();
delete future;
return true;
} else {
return false;
}
}
void BeginningPanel::handle_future()
{
// We don't know which watcher fired: we look through all of them and handle all those that have finished
this->watchers.erase(remove_if(this->watchers.begin(),
this->watchers.end(),
[this](auto x){return this->handle_one_future(x);}),
this->watchers.end());
}
void BeginningPanel::receive_frame(QSharedPointer<FrameAnalysis> frame)
{
this->ui->frame->set_current_frame(frame->frame);
this->ui->tableFrame->set_current_frame(frame->table_frame);
this->ui->refImage->set_current_frame(frame->ref_image);
this->ui->refMask->set_current_frame(frame->ref_mask);
this->ui->frameKeypoints->set_current_frame(frame->frame_matches);
}
void BeginningPanel::receive_settings(const FrameSettings &settings) {
Q_UNUSED(settings);
// FIXME: implement some sane default
}
tuple< Mat, string, string > load_image_thread(QString filename, string variant) {
string cpp_filename = filename.toUtf8().constData();
return make_tuple(imread(cpp_filename), cpp_filename, variant);
}
void BeginningPanel::async_load_image(const string &variant) {
assert(variant == "image" || variant == "mask");
QString title = variant == "image" ? tr("Open reference image") : tr("Open reference mask");
QString filename = QFileDialog::getOpenFileName(this, title, "", tr("Images (*.png *.xpm *.jpg)"));
this->load_image_filename(filename, variant);
}
void BeginningPanel::load_image_filename(QString filename, const string &variant)
{
(variant == "image" ? this->ui->refImageFilename : this->ui->refMaskFilename)->setText(filename.toUtf8().constData());
auto future = QtConcurrent::run(load_image_thread, filename, variant);
this->add_future_watcher(future);
}
void BeginningPanel::on_refImageButton_clicked()
{
async_load_image("image");
}
void BeginningPanel::on_refMaskButton_clicked()
{
async_load_image("mask");
}
void BeginningPanel::on_retrackTableButton_clicked()
{
auto cmds = this->main->edit_commands();
cmds.second->retrack_table = true;
}
void BeginningPanel::on_redetectFeaturesButton_clicked()
{
auto cmds = this->main->edit_commands();
cmds.second->redetect_features = true;
}