6
6
7
7
#include < QScrollArea>
8
8
#include < QVBoxLayout>
9
+ #include < QPushButton>
9
10
#include < QImage>
10
11
#include < QLabel>
11
12
#include < QDialogButtonBox>
12
- #include " assert.h"
13
13
14
+ #include < opencv2/opencv.hpp>
15
+
16
+ #include " assert.h"
14
17
#include < iostream>
15
18
using namespace std ;
16
19
@@ -20,6 +23,16 @@ VerifyDialog::VerifyDialog(std::vector<QImage> &_thumbs, std::vector<QPointF> &_
20
23
21
24
showMaximized ();
22
25
QVBoxLayout *layout = new QVBoxLayout (this );
26
+ if (marker == ALIGN) {
27
+ QHBoxLayout *operations_layout = new QHBoxLayout;
28
+ layout->addLayout (operations_layout);
29
+ QPushButton *reset = new QPushButton (" Reset" );
30
+ operations_layout->addWidget (reset);
31
+ QPushButton *ecc = new QPushButton (" Align" );
32
+ operations_layout->addWidget (ecc);
33
+ connect (reset, SIGNAL (clicked ()), this , SLOT (resetAligns ()));
34
+ connect (ecc, SIGNAL (clicked ()), this , SLOT (alignSamples ()));
35
+ }
23
36
QScrollArea *area = new QScrollArea (this );
24
37
layout->addWidget (area);
25
38
@@ -32,16 +45,49 @@ VerifyDialog::VerifyDialog(std::vector<QImage> &_thumbs, std::vector<QPointF> &_
32
45
33
46
for (size_t i = 0 ; i < thumbs.size (); i++) {
34
47
assert (!thumbs[i].isNull ());
35
- if (marker == REFLECTION ) {
36
- VerifyView *thumb = new VerifyView (thumbs[i], 192 , positions[i], VerifyMarker::REFLECTION);
37
- flowlayout->addWidget (thumb);
38
- } else {
39
- VerifyView *thumb = new VerifyView (thumbs[i], 192 , positions[i], VerifyMarker::ALIGN);
40
- flowlayout->addWidget (thumb);
41
- }
48
+ VerifyView *thumb = new VerifyView (thumbs[i], 192 , positions[i], marker == REFLECTION? VerifyMarker::REFLECTION : VerifyMarker::ALIGN);
49
+ views.push_back (thumb);
50
+ flowlayout->addWidget (thumb);
42
51
}
43
52
44
53
QDialogButtonBox *buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok);
45
54
layout->addWidget (buttonBox);
46
55
connect (buttonBox, SIGNAL (accepted ()), this , SLOT (accept ()));
47
56
}
57
+
58
+ void VerifyDialog::resetAligns () {
59
+ for (QPointF &p: positions)
60
+ p = QPointF (0 , 0 );
61
+ update ();
62
+ }
63
+
64
+ cv::Mat qimg2mat (QImage img) {
65
+ QImage gray = img.convertToFormat (QImage::Format_Grayscale8);
66
+ return cv::Mat (gray.height (), gray.width (), CV_8UC1,
67
+ const_cast <uchar*>(gray.bits ()), gray.bytesPerLine ()).clone ();
68
+ }
69
+
70
+ void VerifyDialog::alignSamples () {
71
+ if (positions.empty ()) return ;
72
+
73
+ cv::Mat ref = qimg2mat (thumbs[0 ]);
74
+
75
+ for (size_t i = 1 ; i < thumbs.size (); i++) {
76
+ cv::Mat warpMat = cv::Mat::eye (2 , 3 , CV_32F);
77
+
78
+ try {
79
+ cv::findTransformECC (ref, qimg2mat (thumbs[i]), warpMat, cv::MOTION_TRANSLATION);
80
+
81
+ positions[i] = QPointF (warpMat.at <float >(0 , 2 ), warpMat.at <float >(1 , 2 ));
82
+ } catch (cv::Exception &e) {
83
+ cerr << e.msg << endl;
84
+ positions[i] = QPointF (0 .0f , 0 .0f );
85
+ }
86
+ }
87
+ update ();
88
+ }
89
+
90
+ void VerifyDialog::update () {
91
+ for (VerifyView *view: views)
92
+ view->set ();
93
+ }
0 commit comments