-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlaucaltagglobject.h
260 lines (207 loc) · 6.94 KB
/
laucaltagglobject.h
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#ifndef LAUCALTAGGLOBJECT_H
#define LAUCALTAGGLOBJECT_H
#ifndef USEHEADLESS
#include <QLabel>
#include <QWidget>
#include <QSpinBox>
#include <QCheckBox>
#include <QGroupBox>
#include <QGridLayout>
#include <QDoubleSpinBox>
#endif
#include <QObject>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLFramebufferObject>
#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/types_c.h"
#include "laumemoryobject.h"
namespace cv
{
using std::vector;
}
#define CALTAGPOLYNOMIALORDER 2
class LAUCalTagGLObject;
class LAUCalTagFilterWidget;
#ifndef USEHEADLESS
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUCalTagFilterWidget : public QWidget
{
Q_OBJECT
public:
LAUCalTagFilterWidget(LAUCalTagGLObject *object, QWidget *parent = nullptr);
void load();
void save();
private:
QSpinBox *iterSpinBox;
QSpinBox *gausSpinBox;
QSpinBox *mednSpinBox;
QDoubleSpinBox *offsetSpinBox;
QSpinBox *minRegionArea; // MINIMUM REGION AREA
QSpinBox *maxRegionArea; // MAXIMUM REGION AREA
QSpinBox *minBoxCount; // MINIMUM BOX AREA
QCheckBox *flipCalTagsFlag; // IS THE TARGET BACKLIT?
};
#endif
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUCalTagGLObject : public QObject, protected QOpenGLFunctions
{
Q_OBJECT
public:
LAUCalTagGLObject(QObject *parent = nullptr);
~LAUCalTagGLObject();
bool isValid() const
{
return (isValidFlag);
}
bool isNull() const
{
return (!isValid());
}
float offset() const
{
return (quantizationOffset);
}
unsigned int medianRadius() const
{
return (medianFilterRadius);
}
unsigned int gaussianRadius() const
{
return (gaussianFilterRadius);
}
unsigned int iterations() const
{
return (iterationCount);
}
int minRegion() const
{
return (minRegionArea);
}
int maxRegion() const
{
return (maxRegionArea);
}
int minBox() const
{
return (minBoxCount);
}
bool flipCalTags() const
{
return (flipCalTagsFlag);
}
void initializeGL();
void processGL(QOpenGLTexture *videoTexture, QOpenGLFramebufferObject *outputFBO = nullptr);
void paintGL();
LAUMemoryObject grabImage();
static QPointF transformPoint(QPointF pt, cv::Mat transformMatrix);
static cv::Mat findBestQuadraticMapping(cv::vector<cv::Point2f> fmPoints, cv::vector<cv::Point2f> toPoints, int width, int height, int order = 4);
static cv::Mat findBestLinearMapping(cv::vector<cv::Point2f> fmPoints, cv::vector<cv::Point2f> toPoints);
#ifndef USEHEADLESS
LAUCalTagFilterWidget *widget(QWidget *parent = nullptr)
{
return (new LAUCalTagFilterWidget(this, parent));
}
#endif
public slots:
void onSetOffset(double val)
{
quantizationOffset = val;
emit update();
}
void onSetMedianRadius(int val)
{
medianFilterRadius = val;
emit update();
}
void onSetGaussianRadius(int val)
{
gaussianFilterRadius = val;
emit update();
}
void onSetIterations(int val)
{
iterationCount = val;
emit update();
}
void onSetMinRegionArea(int val)
{
minRegionArea = val;
emit update();
}
void onSetMaxRegionArea(int val)
{
maxRegionArea = val;
emit update();
}
void onSetMinBoxCount(int val)
{
minBoxCount = val;
emit update();
}
void onSetFlipCalTagsFlag(bool val)
{
flipCalTagsFlag = val;
emit update();
}
private:
typedef struct {
QPoint cr;
QPoint xy;
} Pairing;
bool isValidFlag;
int numRows, numCols;
QList<LAUCalTagGLObject::Pairing> gridPairings; // KEEP TRACK OF THE LAST SET OF GRID POINT PAIRINGS
float quantizationOffset;
unsigned int medianFilterRadius;
unsigned int gaussianFilterRadius;
unsigned int iterationCount;
int minRegionArea; // MINIMUM REGION AREA
int maxRegionArea; // MAXIMUM REGION AREA
int minBoxCount; // MINIMUM BOX AREA
bool flipCalTagsFlag; // IS THE TARGET BACKLIT?
LAUMemoryObject memoryObject[3];
#ifdef QT_DEBUG
LAUMemoryObject debugObject;
#endif
QOpenGLBuffer quadVertexBuffer, quadIndexBuffer;
QOpenGLShaderProgram programA, programB, programC;
QOpenGLShaderProgram programD, programE, programF;
QOpenGLShaderProgram programG, programH, programI;
QOpenGLShaderProgram programJ, programK;
QOpenGLTexture *textureLUT;
QOpenGLFramebufferObject *frameBufferObjectA, *frameBufferObjectB;
QOpenGLFramebufferObject *frameBufferObjectC, *frameBufferObjectD;
void testFBO(QOpenGLFramebufferObject *fbo[], int cols, int rows);
void binarize(QOpenGLTexture *videoTexture, QOpenGLFramebufferObject *fboA, QOpenGLFramebufferObject *fboB, QOpenGLFramebufferObject *fboC);
void sobel(QOpenGLFramebufferObject *fboA, QOpenGLFramebufferObject *fboB);
void cleanUp(QOpenGLFramebufferObject *fboA, QOpenGLFramebufferObject *fboB);
void dilationErosion(QOpenGLFramebufferObject *fboA, QOpenGLFramebufferObject *fboB);
#ifdef QT_DEBUG
cv::Mat detectCalTagGrid(LAUMemoryObject rwObj, LAUMemoryObject inObj, LAUMemoryObject sbObj, LAUMemoryObject dbObj, int minBoxes, int minArea, int maxArea, bool flipCalTags, QList<Pairing> &pairings, bool *okay = nullptr);
#else
cv::Mat detectCalTagGrid(LAUMemoryObject rwObj, LAUMemoryObject inObj, LAUMemoryObject sbObj, int minBoxes, int minArea, int maxArea, bool flipCalTags, QList<Pairing> &pairings, bool *okay = nullptr);
#endif
cv::vector<cv::Point2f> sortPoints(cv::vector<cv::Point> points);
cv::vector<cv::vector<cv::Point2f>> quadArea(cv::Mat sbImage, int minArea, int maxArea);
cv::vector<cv::vector<cv::Point2f>> findSaddles(cv::Mat inImage, cv::vector<cv::vector<cv::Point2f> > quads);
cv::vector<cv::vector<cv::Point2f>> findPattern(cv::Mat inImage, cv::vector<cv::vector<cv::Point2f>> squares, bool flipCalTags);
cv::vector<cv::vector<cv::Point2f>> organizeSquares(cv::vector<cv::vector<cv::Point2f>> squares);
void removeOutlierPoints(cv::vector<cv::Point2f> &fmPoints, cv::vector<cv::Point2f> &toPoints);
bool checkBitCode(int code, cv::Point2f *pt);
float length(cv::Point2f point);
float angle(cv::Point2f point);
signals:
void update();
};
#endif // LAUCALTAGGLOBJECT_H