@@ -13,7 +13,7 @@ namespace photometric_calib {
13
13
14
14
15
15
VignetteCalib::VignetteCalib (std::string folderPath, std::string timePath, std::string cameraFile,
16
- std::string gammaFile, std::string imageFormat, bool silent ) :
16
+ std::string gammaFile, std::string imageFormat) :
17
17
_imageSkip (1 ), _maxIterations(20 ), _outlierTh(15 ), _gridWidth(1000 ), _gridHeight(1000 ), _facW(5 ), _facH(5 ),
18
18
_maxAbsGrad (255 )
19
19
{
@@ -35,12 +35,10 @@ VignetteCalib::VignetteCalib(std::string folderPath, std::string timePath, std::
35
35
_K_p2idx_inverse = _K_p2idx.inv ();
36
36
37
37
_meanExposure = calMeanExposureTime ();
38
-
39
- _silent = silent;
40
38
}
41
39
42
40
VignetteCalib::VignetteCalib (std::string folderPath, std::string timePath, std::string cameraFile,
43
- std::string gammaFile, std::string imageFormat, bool silent, int imageSkip,
41
+ std::string gammaFile, std::string imageFormat, int imageSkip,
44
42
int maxIterations,
45
43
int outlierTh, int gridWidth, int gridHeight, float facW, float facH, int maxAbsGrad) :
46
44
_imageSkip (imageSkip), _maxIterations(maxIterations), _outlierTh(outlierTh), _gridWidth(gridWidth),
@@ -65,8 +63,6 @@ VignetteCalib::VignetteCalib(std::string folderPath, std::string timePath, std::
65
63
_K_p2idx_inverse = _K_p2idx.inv ();
66
64
67
65
_meanExposure = calMeanExposureTime ();
68
-
69
- _silent = silent;
70
66
}
71
67
72
68
float VignetteCalib::getInterpolatedElement (const float *const mat, const float x, const float y, const int width)
@@ -149,7 +145,7 @@ float VignetteCalib::calMeanExposureTime()
149
145
return meanExposure;
150
146
}
151
147
152
- bool VignetteCalib::preCalib (unsigned long id, float *&image, float *&plane2imgX, float *&plane2imgY)
148
+ bool VignetteCalib::preCalib (unsigned long id, float *&image, float *&plane2imgX, float *&plane2imgY, bool debug )
153
149
{
154
150
int wI = imageReader->getWidth ();
155
151
int hI = imageReader->getHeight ();
@@ -232,21 +228,7 @@ bool VignetteCalib::preCalib(unsigned long id, float *&image, float *&plane2imgX
232
228
}
233
229
}
234
230
235
- for (int x = 0 ; x < _gridWidth; x++)
236
- {
237
- for (int y = 0 ; y < _gridHeight; y++)
238
- {
239
- int u_d = (int ) lround (plane2imgX[x + y * _gridWidth] + 0.5 );
240
- int v_d = (int ) lround (plane2imgY[x + y * _gridWidth] + 0.5 );
241
- if (!(u_d > 1 && v_d > 1 && u_d < wI - 2 && v_d < hI - 2 ))
242
- {
243
- plane2imgX[x + y * _gridWidth] = NAN;
244
- plane2imgY[x + y * _gridWidth] = NAN;
245
- }
246
- }
247
- }
248
-
249
- if (!_silent)
231
+ if (debug)
250
232
{
251
233
// debug-plot.
252
234
Mat dbgImg (hI, wI, CV_8UC3);
@@ -299,6 +281,20 @@ bool VignetteCalib::preCalib(unsigned long id, float *&image, float *&plane2imgX
299
281
}
300
282
}
301
283
284
+ for (int x = 0 ; x < _gridWidth; x++)
285
+ {
286
+ for (int y = 0 ; y < _gridHeight; y++)
287
+ {
288
+ int u_d = (int ) lround (plane2imgX[x + y * _gridWidth] + 0.5 );
289
+ int v_d = (int ) lround (plane2imgY[x + y * _gridWidth] + 0.5 );
290
+ if (!(u_d > 1 && v_d > 1 && u_d < wI - 2 && v_d < hI - 2 ))
291
+ {
292
+ plane2imgX[x + y * _gridWidth] = NAN;
293
+ plane2imgY[x + y * _gridWidth] = NAN;
294
+ }
295
+ }
296
+ }
297
+
302
298
imshow (" inRaw" , dbgImg);
303
299
waitKey (1 );
304
300
@@ -310,10 +306,27 @@ bool VignetteCalib::preCalib(unsigned long id, float *&image, float *&plane2imgX
310
306
}
311
307
}
312
308
309
+ else
310
+ {
311
+ for (int x = 0 ; x < _gridWidth; x++)
312
+ {
313
+ for (int y = 0 ; y < _gridHeight; y++)
314
+ {
315
+ int u_d = (int ) lround (plane2imgX[x + y * _gridWidth] + 0.5 );
316
+ int v_d = (int ) lround (plane2imgY[x + y * _gridWidth] + 0.5 );
317
+ if (!(u_d > 1 && v_d > 1 && u_d < wI - 2 && v_d < hI - 2 ))
318
+ {
319
+ plane2imgX[x + y * _gridWidth] = NAN;
320
+ plane2imgY[x + y * _gridWidth] = NAN;
321
+ }
322
+ }
323
+ }
324
+ }
325
+
313
326
return true ;
314
327
}
315
328
316
- void VignetteCalib::calib ()
329
+ void VignetteCalib::calib (bool debug )
317
330
{
318
331
// Create folder for vignette calibration
319
332
if (-1 == system (" rm -rf vignetteCalibResult" ))
@@ -372,7 +385,7 @@ void VignetteCalib::calib()
372
385
float *plane2imgX = NULL ;
373
386
float *plane2imgY = NULL ;
374
387
float *image = NULL ;
375
- if (!preCalib (img, image, plane2imgX, plane2imgY))
388
+ if (!preCalib (img, image, plane2imgX, plane2imgY, debug ))
376
389
{
377
390
continue ;
378
391
}
@@ -413,7 +426,7 @@ void VignetteCalib::calib()
413
426
planeColor[pi] = planeColorFC[pi] / planeColorFF[pi];
414
427
}
415
428
}
416
- if (!_silent )
429
+ if (debug )
417
430
{
418
431
displayImage (planeColor, _gridWidth, _gridWidth, " Plane" );
419
432
}
@@ -430,7 +443,7 @@ void VignetteCalib::calib()
430
443
float *plane2imgX = NULL ;
431
444
float *plane2imgY = NULL ;
432
445
float *image = NULL ;
433
- if (!preCalib (img, image, plane2imgX, plane2imgY))
446
+ if (!preCalib (img, image, plane2imgX, plane2imgY, debug ))
434
447
{
435
448
continue ;
436
449
}
@@ -562,7 +575,7 @@ void VignetteCalib::calib()
562
575
}
563
576
564
577
// ================================ Store Vignette Image =======================================
565
- if (!_silent )
578
+ if (debug )
566
579
{
567
580
displayImageV (vignetteFactorTT, wI, hI, " VignetteSmoothed" );
568
581
}
@@ -572,7 +585,7 @@ void VignetteCalib::calib()
572
585
imwrite (" vignetteCalibResult/vignetteSmoothed.png" , wrapSmoothed16);
573
586
waitKey (50 );
574
587
575
- if (!_silent )
588
+ if (debug )
576
589
{
577
590
displayImageV (vignetteFactor, wI, hI, " VignetteOrg" );
578
591
}
@@ -594,8 +607,10 @@ void VignetteCalib::calib()
594
607
delete[] vignetteFactorCT;
595
608
}
596
609
597
- void VignetteCalib::calibFast ()
610
+ void VignetteCalib::calibFast (bool debug )
598
611
{
612
+ std::cout<<" Fast mode! This requires large memory (10GB+)!" <<std::endl;
613
+
599
614
if (-1 == system (" rm -rf vignetteCalibResult" ))
600
615
{
601
616
std::cout << " could not delete old vignetteCalibResult folder!" << std::endl;
@@ -694,22 +709,7 @@ void VignetteCalib::calibFast()
694
709
695
710
images.push_back (image);
696
711
697
- for (int x = 0 ; x < _gridWidth; x++)
698
- {
699
- for (int y = 0 ; y < _gridHeight; y++)
700
- {
701
- int u_d = (int ) lround (plane2imgX[x + y * _gridWidth] + 0.5 );
702
- int v_d = (int ) lround (plane2imgY[x + y * _gridWidth] + 0.5 );
703
-
704
- if (!(u_d > 1 && v_d > 1 && u_d < wI - 2 && v_d < hI - 2 ))
705
- {
706
- plane2imgX[x + y * _gridWidth] = NAN;
707
- plane2imgY[x + y * _gridWidth] = NAN;
708
- }
709
- }
710
- }
711
-
712
- if (!_silent)
712
+ if (debug)
713
713
{
714
714
// debug-plot.
715
715
Mat dbgImg (hI, wI, CV_8UC3);
@@ -764,6 +764,21 @@ void VignetteCalib::calibFast()
764
764
}
765
765
}
766
766
767
+ for (int x = 0 ; x < _gridWidth; x++)
768
+ {
769
+ for (int y = 0 ; y < _gridHeight; y++)
770
+ {
771
+ int u_d = (int ) lround (plane2imgX[x + y * _gridWidth] + 0.5 );
772
+ int v_d = (int ) lround (plane2imgY[x + y * _gridWidth] + 0.5 );
773
+
774
+ if (!(u_d > 1 && v_d > 1 && u_d < wI - 2 && v_d < hI - 2 ))
775
+ {
776
+ plane2imgX[x + y * _gridWidth] = NAN;
777
+ plane2imgY[x + y * _gridWidth] = NAN;
778
+ }
779
+ }
780
+ }
781
+
767
782
imshow (" inRaw" , dbgImg);
768
783
769
784
if (rand () % 40 == 0 )
@@ -776,6 +791,24 @@ void VignetteCalib::calibFast()
776
791
waitKey (1 );
777
792
}
778
793
794
+ else
795
+ {
796
+ for (int x = 0 ; x < _gridWidth; x++)
797
+ {
798
+ for (int y = 0 ; y < _gridHeight; y++)
799
+ {
800
+ int u_d = (int ) lround (plane2imgX[x + y * _gridWidth] + 0.5 );
801
+ int v_d = (int ) lround (plane2imgY[x + y * _gridWidth] + 0.5 );
802
+
803
+ if (!(u_d > 1 && v_d > 1 && u_d < wI - 2 && v_d < hI - 2 ))
804
+ {
805
+ plane2imgX[x + y * _gridWidth] = NAN;
806
+ plane2imgY[x + y * _gridWidth] = NAN;
807
+ }
808
+ }
809
+ }
810
+ }
811
+
779
812
p2imgX.push_back (plane2imgX);
780
813
p2imgY.push_back (plane2imgY);
781
814
@@ -858,7 +891,7 @@ void VignetteCalib::calibFast()
858
891
planeColor[pi] = planeColorFC[pi] / planeColorFF[pi];
859
892
}
860
893
}
861
- if (!_silent )
894
+ if (debug )
862
895
{
863
896
displayImage (planeColor, _gridWidth, _gridWidth, " Plane" );
864
897
}
@@ -1013,7 +1046,7 @@ void VignetteCalib::calibFast()
1013
1046
}
1014
1047
1015
1048
// ================================ Store Vignette Image =======================================
1016
- if (!_silent )
1049
+ if (debug )
1017
1050
{
1018
1051
displayImageV (vignetteFactorTT, wI, hI, " VignetteSmoothed" );
1019
1052
}
@@ -1023,7 +1056,7 @@ void VignetteCalib::calibFast()
1023
1056
imwrite (" vignetteCalibResult/vignetteSmoothed.png" , wrapSmoothed16);
1024
1057
waitKey (50 );
1025
1058
1026
- if (!_silent )
1059
+ if (debug )
1027
1060
{
1028
1061
displayImageV (vignetteFactor, wI, hI, " VignetteOrg" );
1029
1062
}
0 commit comments