-
Notifications
You must be signed in to change notification settings - Fork 52
/
ChessboradStruct.cpp
785 lines (700 loc) · 19.3 KB
/
ChessboradStruct.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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
/* Copyright 2017 onlyliu([email protected]). */
/* */
/* Automatic Camera and Range Sensor Calibration using a single Shot */
/* this project realize the papar: Automatic Camera and Range Sensor */
/* Calibration using a single Shot */
#include "ChessboradStruct.h"
#include <fstream>
#include <limits>
#include<numeric>
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
ChessboradStruct::ChessboradStruct()
{
}
ChessboradStruct::~ChessboradStruct()
{
}
inline float distv(cv::Vec2f a, cv::Vec2f b)
{
return std::sqrt((a[0] - b[0])*(a[0] - b[0]) + (a[1] - b[1])*(a[1] - b[1]));
}
inline float mean_l(std::vector<float> &resultSet)
{
double sum = std::accumulate(std::begin(resultSet), std::end(resultSet), 0.0);
double mean = sum / resultSet.size(); //ŸùÖµ
return mean;
}
inline float stdev_l(std::vector<float> &resultSet, float &mean)
{
double accum = 0.0;
mean = mean_l(resultSet);
std::for_each(std::begin(resultSet), std::end(resultSet), [&](const double d) {
accum += (d - mean)*(d - mean);
});
double stdev = sqrt(accum / (resultSet.size() - 1)); //·œ²î
return stdev;
}
inline float stdevmean(std::vector<float> &resultSet)
{
float stdvalue, meanvalue;
stdvalue = stdev_l(resultSet, meanvalue);
return stdvalue / meanvalue;
}
int ChessboradStruct::directionalNeighbor(int idx, cv::Vec2f v, cv::Mat chessboard, Corners& corners, int& neighbor_idx, float& min_dist)
{
#if 1
// list of neighboring elements, which are currently not in use
std::vector<int> unused(corners.p.size());
for (int i = 0; i < unused.size(); i++)
{
unused[i] = i;
}
for (int i = 0; i < chessboard.rows; i++)
for (int j = 0; j < chessboard.cols; j++)
{
int xy = chessboard.at<int>(i, j);
if (xy >= 0)
{
unused[xy] = -1;
}
}
int nsize = unused.size();
for (int i = 0; i < nsize;)
{
if (unused[i] < 0)
{
std::vector<int>::iterator iter = unused.begin() + i;
unused.erase(iter);
i = 0;
nsize = unused.size();
continue;
}
i++;
}
std::vector<float> dist_edge;
std::vector<float> dist_point;
cv::Vec2f idxp = cv::Vec2f(corners.p[idx].x, corners.p[idx].y);
// direction and distance to unused corners
for (int i = 0; i < unused.size(); i++)
{
int ind = unused[i];
cv::Vec2f diri = cv::Vec2f(corners.p[ind].x, corners.p[ind].y) - idxp;
float disti = diri[0] * v[0] + diri[1] * v[1];
cv::Vec2f de = diri - disti*v;
dist_edge.push_back(distv(de, cv::Vec2f(0, 0)));
// distances
dist_point.push_back(disti);
}
#else
// list of neighboring elements, which are currently not in use
std::vector<int> unused(corners.p.size());
for (int i = 0; i < unused.size(); i++)
{
unused[i] = i;
}
for (int i = 0; i < chessboard.rows; i++)
for (int j = 0; j < chessboard.cols; j++)
{
int xy = chessboard.at<int>(i, j);
if (xy >= 0)
{
unused[xy] = -1;//flag the used idx
}
}
std::vector<float> dist_edge;
std::vector<float> dist_point;
cv::Vec2f idxp = cv::Vec2f(corners.p[idx].x, corners.p[idx].y);
// direction and distance to unused corners
for (int i = 0; i < corners.p.size(); i++)
{
if (unused[i] == -1)
{
dist_point.push_back(std::numeric_limits<float>::max());
dist_edge.push_back(0);
continue;
}
cv::Vec2f diri = cv::Vec2f(corners.p[i].x, corners.p[i].y) - idxp;
float disti = diri[0] * v[0] + diri[1] * v[1];
cv::Vec2f de = diri - disti*v;
dist_edge.push_back(distv(de, cv::Vec2f(0, 0)));
// distances
dist_point.push_back(disti);
}
#endif
// find best neighbor
int min_idx = 0;
min_dist = std::numeric_limits<float>::max();
//min_dist = dist_point[0] + 5 * dist_edge[0];
for (int i = 0; i < dist_point.size(); i++)
{
if (dist_point[i] > 0)
{
float m = dist_point[i] + 5 * dist_edge[i];
if (m < min_dist)
{
min_dist = m;
min_idx = i;
}
}
}
neighbor_idx = unused[min_idx];
return 1;
}
cv::Mat ChessboradStruct::initChessboard(Corners& corners, int idx)
{
// return if not enough corners
if (corners.p.size() < 9)
{
logd("not enough corners!\n");
chessboard.release();//return empty!
return chessboard;
}
// init chessboard hypothesis
chessboard = -1 * cv::Mat::ones(3, 3, CV_32S);
// extract feature index and orientation(central element)
cv::Vec2f v1 = corners.v1[idx];
cv::Vec2f v2 = corners.v2[idx];
chessboard.at<int>(1, 1) = idx;
std::vector<float> dist1(2), dist2(6);
// find left / right / top / bottom neighbors
directionalNeighbor(idx, +1 * v1, chessboard, corners, chessboard.at<int>(1, 2), dist1[0]);
directionalNeighbor(idx, -1 * v1, chessboard, corners, chessboard.at<int>(1, 0), dist1[1]);
directionalNeighbor(idx, +1 * v2, chessboard, corners, chessboard.at<int>(2, 1), dist2[0]);
directionalNeighbor(idx, -1 * v2, chessboard, corners, chessboard.at<int>(0, 1), dist2[1]);
// find top - left / top - right / bottom - left / bottom - right neighbors
directionalNeighbor(chessboard.at<int>(1, 0), -1 * v2, chessboard, corners, chessboard.at<int>(0, 0), dist2[2]);
directionalNeighbor(chessboard.at<int>(1, 0), +1 * v2, chessboard, corners, chessboard.at<int>(2, 0), dist2[3]);
directionalNeighbor(chessboard.at<int>(1, 2), -1 * v2, chessboard, corners, chessboard.at<int>(0, 2), dist2[4]);
directionalNeighbor(chessboard.at<int>(1, 2), +1 * v2, chessboard, corners, chessboard.at<int>(2, 2), dist2[5]);
// initialization must be homogenously distributed
bool sigood = false;
sigood = sigood||(dist1[0]<0) || (dist1[1]<0);
sigood = sigood || (dist2[0]<0) || (dist2[1]<0) || (dist2[2]<0) || (dist2[3]<0) || (dist2[4]<0) || (dist2[5]<0);
sigood = sigood || (stdevmean(dist1) > 0.3) || (stdevmean(dist2) > 0.3);
if (sigood == true)
{
chessboard.release();
return chessboard;
}
return chessboard;
}
float ChessboradStruct::chessboardEnergy(cv::Mat chessboard, Corners& corners)
{
float lamda = m_lamda;
//energy: number of corners
float E_corners = -1 * chessboard.size().area();
//energy: structur
float E_structure = 0;
//walk through rows
for (int i = 0; i < chessboard.rows; i++)
for (int j = 0; j < chessboard.cols-2; j++)
{
std::vector<cv::Vec2f> x;
float E_structure0 = 0;
for (int k = j; k <= j + 2; k++)
{
int n = chessboard.at<int>(i, k);
x.push_back(corners.p[n]);
}
E_structure0 = distv(x[0] + x[2] - 2 * x[1], cv::Vec2f(0,0));
float tv = distv(x[0] - x[2], cv::Vec2f(0, 0));
E_structure0 = E_structure0 / tv;
if (E_structure < E_structure0)
E_structure = E_structure0;
}
//walk through columns
for (int i = 0; i < chessboard.cols; i++)
for (int j = 0; j < chessboard.rows-2; j++)
{
std::vector<cv::Vec2f> x;
float E_structure0 = 0;
for (int k = j; k <= j + 2; k++)
{
int n = chessboard.at<int>(k, i);
x.push_back(corners.p[n]);
}
E_structure0 = distv(x[0] + x[2] - 2 * x[1], cv::Vec2f(0, 0));
float tv = distv(x[0] - x[2], cv::Vec2f(0, 0));
E_structure0 = E_structure0 / tv;
if (E_structure < E_structure0)
E_structure = E_structure0;
}
// final energy
float E = E_corners + lamda*chessboard.size().area()*E_structure;
return E;
}
// replica prediction(new)
void ChessboradStruct::predictCorners(std::vector<cv::Vec2f>& p1, std::vector<cv::Vec2f>& p2,
std::vector<cv::Vec2f>& p3, std::vector<cv::Vec2f>& pred)
{
cv::Vec2f v1, v2;
float a1, a2, a3;
float s1, s2, s3;
pred.resize(p1.size());
for (int i = 0; i < p1.size(); i++)
{
// compute vectors
v1 = p2[i] - p1[i];
v2 = p3[i] - p2[i];
// predict angles
a1 = atan2(v1[1], v1[0]);
a2 = atan2(v2[1], v2[0]);
a3 = 2.0 * a2 - a1;
//predict scales
s1 = distv(v1, cv::Vec2f(0, 0));
s2 = distv(v2, cv::Vec2f(0, 0));
s3 = 2 * s2 - s1;
pred[i] = p3[i] + 0.75*s3*cv::Vec2f(cos(a3), sin(a3));
}
}
void ChessboradStruct::assignClosestCorners(std::vector<cv::Vec2f>&cand, std::vector<cv::Vec2f>&pred, std::vector<int> &idx)
{
//return error if not enough candidates are available
if (cand.size() < pred.size())
{
idx.resize(1);
idx[0] = -1;
return;
}
idx.resize(pred.size());
//build distance matrix
cv::Mat D = cv::Mat::zeros(cand.size(), pred.size(), CV_32FC1);
float mind = FLT_MAX;
for (int i = 0; i < D.cols; i++)//ÁÐÓÅÏÈ
{
cv::Vec2f delta;
for (int j = 0; j < D.rows; j++)
{
delta = cand[j] - pred[i];
float s = distv(delta, cv::Vec2f(0, 0));
D.at<float>(j, i) = s;
if (s < mind)
{
mind = s;
}
}
}
// search greedily for closest corners
for (int k = 0; k < pred.size(); k++)
{
bool isbreak = false;
for (int i = 0; i < D.rows; i++)
{
for (int j = 0; j < D.cols; j++)
{
if (fabs(D.at<float>(i, j) - mind) < 10e-10)
{
idx[j] = i;
for (int m = 0; m < D.cols; m++)
{
D.at<float>(i, m) = FLT_MAX;
}
for (int m = 0; m < D.rows; m++)
{
D.at<float>(m,j) = FLT_MAX;
}
isbreak = true;
break;
}
}
if (isbreak == true)
break;
}
mind = FLT_MAX;
for (int i = 0; i < D.rows; i++)
{
for (int j = 0; j < D.cols; j++)
{
if (D.at<float>(i, j) < mind)
{
mind = D.at<float>(i, j);
}
}
}
}
}
cv::Mat ChessboradStruct::growChessboard(cv::Mat chessboard, Corners& corners, int border_type)
{
if (chessboard.empty() == true)
{
return chessboard;
}
std::vector<cv::Point2f> p = corners.p;
// list of unused feature elements
std::vector<int> unused(p.size());
for (int i = 0; i < unused.size(); i++)
{
unused[i] = i;
}
for (int i = 0; i < chessboard.rows; i++)
for (int j = 0; j < chessboard.cols; j++)
{
int xy = chessboard.at<int>(i, j);
if (xy >= 0)
{
unused[xy] = -1;
}
}
int nsize = unused.size();
for (int i = 0; i < nsize; )
{
if (unused[i] < 0)
{
std::vector<int>::iterator iter = unused.begin() + i;
unused.erase(iter);
i = 0;
nsize = unused.size();
continue;
}
i++;
}
// candidates from unused corners
std::vector<cv::Vec2f> cand;
for (int i = 0; i < unused.size(); i++)
{
cand.push_back(corners.p[unused[i]]);
}
// switch border type 1..4
cv::Mat chesstemp;
switch (border_type)
{
case 0:
{
std::vector<cv::Vec2f> p1, p2, p3,pred;
for (int row = 0; row < chessboard.rows; row++)
for (int col = 0; col < chessboard.cols; col++)
{
if (col == chessboard.cols - 3)
{
int ij = chessboard.at<int>(row, col);
p1.push_back(cv::Vec2f(p[ij]));
}
if (col == chessboard.cols - 2)
{
int ij = chessboard.at<int>(row, col);
p2.push_back(cv::Vec2f(p[ij]));
}
if (col == chessboard.cols - 1)
{
int ij = chessboard.at<int>(row, col);
p3.push_back(cv::Vec2f(p[ij]));
}
}
std::vector<int> idx;
predictCorners(p1, p2, p3, pred);
assignClosestCorners(cand, pred, idx);
if (idx[0] < 0)
{
return chessboard;
}
cv::copyMakeBorder(chessboard, chesstemp, 0, 0, 0, 1, 0,0);
for (int i = 0; i < chesstemp.rows; i++)
{
chesstemp.at<int>(i, chesstemp.cols - 1) = unused[idx[i]];//ÓÒ
}
chessboard = chesstemp.clone();
break;
}
case 1:
{
std::vector<cv::Vec2f> p1, p2, p3, pred;
for (int row = 0; row < chessboard.rows; row++)
for (int col = 0; col < chessboard.cols; col++)
{
if (row == chessboard.rows - 3)
{
int ij = chessboard.at<int>(row, col);
p1.push_back(cv::Vec2f(p[ij]));
}
if (row == chessboard.rows - 2)
{
int ij = chessboard.at<int>(row, col);
p2.push_back(cv::Vec2f(p[ij]));
}
if (row == chessboard.rows - 1)
{
int ij = chessboard.at<int>(row, col);
p3.push_back(cv::Vec2f(p[ij]));
}
}
std::vector<int> idx;
predictCorners(p1, p2, p3, pred);
assignClosestCorners(cand, pred, idx);
if (idx[0] < 0)
{
return chessboard;
}
cv::copyMakeBorder(chessboard, chesstemp, 0, 1, 0, 0, 0, 0);
for (int i = 0; i < chesstemp.cols; i++)
{
chesstemp.at<int>(chesstemp.rows - 1, i) = unused[idx[i]];//ÏÂ
}
chessboard = chesstemp.clone();
break;
}
case 2:
{
std::vector<cv::Vec2f> p1, p2, p3, pred;
for (int row = 0; row < chessboard.rows; row++)
for (int col = 0; col < chessboard.cols; col++)
{
if (col == 2)
{
int ij = chessboard.at<int>(row, col);
p1.push_back(cv::Vec2f(p[ij]));
}
if (col == 1)
{
int ij = chessboard.at<int>(row, col);
p2.push_back(cv::Vec2f(p[ij]));
}
if (col == 0)
{
int ij = chessboard.at<int>(row, col);
p3.push_back(cv::Vec2f(p[ij]));
}
}
std::vector<int> idx;
predictCorners(p1, p2, p3, pred);
assignClosestCorners(cand, pred, idx);
if (idx[0] < 0)
{
return chessboard;
}
cv::copyMakeBorder(chessboard, chesstemp, 0, 0, 1, 0, 0, 0);//×ó
for (int i = 0; i < chesstemp.rows; i++)
{
chesstemp.at<int>(i, 0) = unused[idx[i]];
}
chessboard = chesstemp.clone();
break;
}
case 3:
{
std::vector<cv::Vec2f> p1, p2, p3, pred;
for (int row = 0; row < chessboard.rows; row++)
for (int col = 0; col < chessboard.cols; col++)
{
if (row == 2)
{
int ij = chessboard.at<int>(row, col);
p1.push_back(cv::Vec2f(p[ij]));
}
if (row == 1)
{
int ij = chessboard.at<int>(row, col);
p2.push_back(cv::Vec2f(p[ij]));
}
if (row == 0)
{
int ij = chessboard.at<int>(row, col);
p3.push_back(cv::Vec2f(p[ij]));
}
}
std::vector<int> idx;
predictCorners(p1, p2, p3, pred);
assignClosestCorners(cand, pred, idx);
if (idx[0] < 0)
{
return chessboard;
}
cv::copyMakeBorder(chessboard, chesstemp, 1, 0, 0, 0, 0, 0);//ÉÏ
for (int i = 0; i < chesstemp.cols; i++)
{
chesstemp.at<int>(0, i) = unused[idx[i]];
}
chessboard = chesstemp.clone();
break;
}
default:
break;
}
return chessboard;
}
void ChessboradStruct::chessboardsFromCorners( Corners& corners, std::vector<cv::Mat>& chessboards, float lamda)
{
logd("Structure recovery:\n");
m_lamda = lamda;
for (int i = 0; i < corners.p.size(); i++)
{
if (i % 128 == 0)
printf("%d, %d\n", i, corners.p.size());
cv::Mat csbd = initChessboard(corners, i);
if (csbd.empty() == true)
{
continue;
}
float E =chessboardEnergy(csbd, corners);
if (E > 0){ continue; }
int s = 0;
//try growing chessboard
while (true)
{
s++;
// compute current energy
float energy = chessboardEnergy(chessboard, corners);
std::vector<cv::Mat> proposal(4);
std::vector<float> p_energy(4);
//compute proposals and energies
for (int j = 0; j < 4; j++)
{
proposal[j] = growChessboard(chessboard, corners, j);
p_energy[j] = chessboardEnergy(proposal[j], corners);
}
// find best proposal
float min_value = p_energy[0];
int min_idx = 0;
for (int i0 = 1; i0 < p_energy.size(); i0++)
{
if (min_value > p_energy[i0])
{
min_value = p_energy[i0];
min_idx = i0;
}
}
// accept best proposal, if energy is reduced
cv::Mat chessboardt;
if (p_energy[min_idx] < energy)
{
chessboardt = proposal[min_idx];
chessboard = chessboardt.clone();
}
else
{
break;
}
}//end while
if (chessboardEnergy(chessboard, corners) < -10)
{
//check if new chessboard proposal overlaps with existing chessboards
cv::Mat overlap = cv::Mat::zeros(cv::Size(2,chessboards.size()), CV_32FC1);
for (int j = 0; j < chessboards.size(); j++)
{
bool isbreak = false;
for (int k = 0; k < chessboards[j].size().area(); k++)
{
int refv = chessboards[j].at<int>(k / chessboards[j].cols, k%chessboards[j].cols);
for (int l = 0; l < chessboard.size().area(); l++)
{
int isv = chessboard.at<int>(l/ chessboard.cols, l%chessboard.cols);
if (refv == isv)
{
overlap.at<float>(j, 0) = 1.0;
float s = chessboardEnergy(chessboards[j], corners);
overlap.at<float>(j, 1) = s;
isbreak = true;
break;
}
}
// if (isbreak == true)
// {
// break;
// }
}
//if (isbreak == true)
//{
// break;
//}
}//endfor
// add chessboard(and replace overlapping if neccessary)
bool isoverlap = false;
for (int i0 = 0; i0 < overlap.rows; i0++)
{
if (overlap.empty() == false)
{
if (fabs(overlap.at<float>(i0, 0)) > 0.000001)// ==1
{
isoverlap = true;
break;
}
}
}
if (isoverlap == false)
{
chessboards.push_back(chessboard);
}
else
{
bool flagpush = true;
std::vector<bool> flagerase(overlap.rows);
for (int m = 0; m < flagerase.size(); m++)
{
flagerase[m] = false;
}
float ce = chessboardEnergy(chessboard, corners);
for (int i1 = 0; i1 < overlap.rows; i1++)
{
if (fabs(overlap.at<float>(i1, 0)) > 0.0001)// ==1//ÓÐÖصþ
{
bool isb1 = overlap.at<float>(i1, 1) > ce;
int a = int(overlap.at<float>(i1, 1) * 1000);
int b = int(ce * 1000);
bool isb2 = a > b;
if (isb1 != isb2)
printf("find bug!\n");
if (isb2)
{
flagerase[i1] = true;
}
else
{
flagpush = false;
// break;
}//endif
}//endif
}//end for
if (flagpush == true)
{
for (int i1 = 0; i1 < chessboards.size();)
{
std::vector<cv::Mat>::iterator it = chessboards.begin() + i1;
std::vector<bool>::iterator it1 = flagerase.begin() + i1;
if (*it1 == true)
{
chessboards.erase(it);
flagerase.erase(it1);
i1 = 0;
}
i1++;
}
chessboards.push_back(chessboard);
}
}//endif
}//endif
}//end for
}
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
void ChessboradStruct::drawchessboard(cv::Mat img, Corners& corners, std::vector<cv::Mat>& chessboards, char * title, int t_, cv::Rect rect)
{
printf("end!\n");
cv::RNG rng(0xFFFFFFFF);
std::string s("If it's useful, please give a star ^-^.");
std::string s1("https://github.com/onlyliucat\n");
std::cout<<BOLDBLUE<<s<<std::endl<<BOLDGREEN<<s1<<std::endl;
cv::Mat disp = img.clone();
if (disp.channels() < 3)
cv::cvtColor(disp, disp, CV_GRAY2BGR);
float scale = 0.3;
int n = 8;
if (img.rows < 2000 || img.cols < 2000)
{
scale = 1;
n = 2;
}
for (int k = 0; k < chessboards.size(); k++)
{
cv::Scalar s(rng.uniform(0.0, 1.0), rng.uniform(0.0, 1.0), rng.uniform(0.0, 1.0));
s = s * 255;
for (int i = 0; i < chessboards[k].rows; i++)
for (int j = 0; j < chessboards[k].cols; j++)
{
int d = chessboards[k].at<int>(i, j);
cv::circle(disp, cv::Point2f(corners.p[d].x + rect.x, corners.p[d].y + rect.y), n, s, n);
}
}
cv::Mat SmallMat;
cv::resize(disp, SmallMat, cv::Size(), scale, scale);
cv::namedWindow(title);
cv::imshow(title, SmallMat);
cv::waitKey(t_);
}