forked from githubdoe/DFTFringe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratetargetdlg.cpp
More file actions
233 lines (198 loc) · 5.69 KB
/
Copy pathgeneratetargetdlg.cpp
File metadata and controls
233 lines (198 loc) · 5.69 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "generatetargetdlg.h"
#include "ui_generatetargetdlg.h"
#include <QDesktopWidget>
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <QPrinter>
#include <QPrintDialog>
#include <QPainter>
#include <QDebug>
#include <QSettings>
using namespace cv;
using namespace std;
generateTargetDlg::generateTargetDlg(QWidget *parent) :
QDialog(parent),m_units(INCHES),
ui(new Ui::generateTargetDlg)
{
ui->setupUi(this);
m_dpix = qApp->desktop()->physicalDpiX();
m_dpiy = qApp->desktop()->physicalDpiY();
ui->printerGroup->hide();
QSettings set;
ui->rows->setValue(set.value("target rows", 10).toInt());
}
generateTargetDlg::~generateTargetDlg()
{
delete ui;
}
void generateTargetDlg::on_generate_clicked()
{
QSettings set;
set.setValue("target rows", ui->rows->value());
int blockSize = m_dpix/2;
int hsize;
int vsize;
if (ui->fullScreen->isChecked()){
// make sure sizes are even
hsize = qApp->desktop()->width();
hsize/=2;
hsize *= 2;
vsize = qApp->desktop()->height();
vsize /=2;
vsize *= 2;
}
else {
double mul = 1.;
switch (m_units){
case MM:
mul = 96./25.4;
break;
case INCHES:
mul = 96;
break;
case PIXELS:
break;
}
hsize = ui->width->value() * mul;
vsize = ui->height->value() * mul;
}
blockSize = min(hsize,vsize) / (ui->rows->value());
int blocks = hsize/blockSize;
hsize = blocks * blockSize;
blocks = vsize/blockSize;
vsize = blocks * blockSize;
Mat chessBoard(vsize,hsize,CV_8UC1,Scalar(255));
unsigned char color=0;
int vcnt = 0;
int hcnt;
int lastx = hsize - (ui->useChecker->isChecked() ? blockSize : .5 * blockSize);
int lasty = vsize - (ui->useChecker->isChecked() ? blockSize : .5 * blockSize);
for(int i=blockSize/2; i<= lasty; i=i+blockSize){
++vcnt;
hcnt = 0;
for(int j= blockSize/2; j <= lastx; j=j+blockSize){
++hcnt;
if (ui->useChecker->isChecked()){
Mat ROI=chessBoard(Rect(j,i,blockSize,blockSize));
ROI.setTo(Scalar::all(color));
color=~color;
}
else if (ui->lineGridRb->isChecked()){
line(chessBoard, Point(j,i),Point(hsize-blockSize/2, i),Scalar(0,0,0),2);
line(chessBoard, Point(j,blockSize/2), Point(j,vsize-blockSize/2), Scalar(0,0,0),2);
}
else {
circle(chessBoard, Point(j ,i), blockSize/3, Scalar(0,0,0), -1);
}
}
if ( (hcnt %2) == 0)
color=~color;
}
if (ui->useChecker->isChecked()){
--hcnt;
--vcnt;
}
putText(chessBoard, QString().sprintf("%d X %d", hcnt, vcnt).toStdString().c_str(),
Point(40,20),1,1,cv::Scalar(100, 100,100));
//pyrDown(chessBoard,chessBoard);
imshow("Grid pattern", chessBoard);
waitKey(1);
/* debug to see contours of grid
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// Find contours
findContours( chessBoard.clone(), contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
RNG rng(12345);
/// Draw contours
Mat drawing = Mat::zeros( chessBoard.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}
/// Show in a window
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
imshow( "Contours", drawing );
waitKey(1);
*/
}
void generateTargetDlg::on_printed_clicked(bool checked)
{
if (!checked)
ui->printerGroup->hide();
else
ui->printerGroup->show();
on_generate_clicked();
}
void generateTargetDlg::on_fullScreen_clicked(bool checked)
{
if (checked)
ui->printerGroup->hide();
else
ui->printerGroup->show();
on_generate_clicked();
}
void generateTargetDlg::on_rows_valueChanged(int arg1)
{
on_generate_clicked();
}
void generateTargetDlg::on_useChecker_toggled(bool checked)
{
on_generate_clicked();
}
void generateTargetDlg::on_lineGridRb_clicked()
{
on_generate_clicked();
}
void generateTargetDlg::on_usePixels_clicked(bool checked)
{
double mul = 1.;
switch (m_units){
case MM:
mul = 96./25.4;
break;
case INCHES:
mul = 96.;
break;
case PIXELS:
break;
}
ui->width->setValue((int)(ui->width->value() * mul));
ui->height->setValue((int)(ui->height->value() * mul));
m_units = PIXELS;
}
void generateTargetDlg::on_useInches_clicked(bool checked)
{
double mul = 1.;
switch (m_units){
case MM:
mul = 1./25.4;
break;
case INCHES:
break;
case PIXELS:
mul = 1./96.;
break;
}
ui->width->setValue(ui->width->value() * mul);
ui->height->setValue(ui->height->value() * mul);
m_units = INCHES;
}
void generateTargetDlg::on_useMm_clicked(bool checked)
{
double mul = 1.;
switch (m_units){
case MM:
break;
case INCHES:
mul = 25.4;
break;
case PIXELS:
mul = 25.4/96.;
break;
}
ui->width->setValue(ui->width->value() * mul);
ui->height->setValue(ui->height->value() * mul);
m_units = MM;
}