Skip to content

Commit ff2187c

Browse files
committed
Change parameter bool silent of the constructor to the parameter of method calib() and calibFast(). And also change 'silent' to 'debug'.
1 parent c1d3f5c commit ff2187c

File tree

2 files changed

+86
-54
lines changed

2 files changed

+86
-54
lines changed

modules/photometric_calib/include/opencv2/photometric_calib/VignetteCalib.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class CV_EXPORTS VignetteCalib
1717
{
1818
public:
1919
VignetteCalib(std::string folderPath, std::string timePath, std::string cameraFile, std::string gammaFile,
20-
std::string imageFormat, bool silent);
20+
std::string imageFormat);
2121

2222
VignetteCalib(std::string folderPath, std::string timePath, std::string cameraFile, std::string gammaFile,
23-
std::string imageFormat, bool silent, int imageSkip, int maxIterations, int outlierTh,
23+
std::string imageFormat, int imageSkip, int maxIterations, int outlierTh,
2424
int gridWidth, int gridHeight, float facW, float facH, int maxAbsGrad);
2525

2626
virtual ~VignetteCalib();
@@ -34,11 +34,11 @@ class CV_EXPORTS VignetteCalib
3434

3535
void displayImageV(float *I, int w, int h, std::string name);
3636

37-
bool preCalib(unsigned long id, float *&image, float *&plane2imgX, float *&plane2imgY);
37+
bool preCalib(unsigned long id, float *&image, float *&plane2imgX, float *&plane2imgY, bool debug);
3838

39-
void calib();
39+
void calib(bool debug);
4040

41-
void calibFast();
41+
void calibFast(bool debug);
4242

4343
private:
4444
int _imageSkip;
@@ -65,7 +65,6 @@ class CV_EXPORTS VignetteCalib
6565
GammaRemover *gammaRemover;
6666

6767
float _meanExposure;
68-
bool _silent;
6968
};
7069

7170
} // namespace photometric_calib

modules/photometric_calib/src/VignetteCalib.cpp

Lines changed: 81 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace photometric_calib {
1313

1414

1515
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) :
1717
_imageSkip(1), _maxIterations(20), _outlierTh(15), _gridWidth(1000), _gridHeight(1000), _facW(5), _facH(5),
1818
_maxAbsGrad(255)
1919
{
@@ -35,12 +35,10 @@ VignetteCalib::VignetteCalib(std::string folderPath, std::string timePath, std::
3535
_K_p2idx_inverse = _K_p2idx.inv();
3636

3737
_meanExposure = calMeanExposureTime();
38-
39-
_silent = silent;
4038
}
4139

4240
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,
4442
int maxIterations,
4543
int outlierTh, int gridWidth, int gridHeight, float facW, float facH, int maxAbsGrad) :
4644
_imageSkip(imageSkip), _maxIterations(maxIterations), _outlierTh(outlierTh), _gridWidth(gridWidth),
@@ -65,8 +63,6 @@ VignetteCalib::VignetteCalib(std::string folderPath, std::string timePath, std::
6563
_K_p2idx_inverse = _K_p2idx.inv();
6664

6765
_meanExposure = calMeanExposureTime();
68-
69-
_silent = silent;
7066
}
7167

7268
float VignetteCalib::getInterpolatedElement(const float *const mat, const float x, const float y, const int width)
@@ -149,7 +145,7 @@ float VignetteCalib::calMeanExposureTime()
149145
return meanExposure;
150146
}
151147

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)
153149
{
154150
int wI = imageReader->getWidth();
155151
int hI = imageReader->getHeight();
@@ -232,21 +228,7 @@ bool VignetteCalib::preCalib(unsigned long id, float *&image, float *&plane2imgX
232228
}
233229
}
234230

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)
250232
{
251233
// debug-plot.
252234
Mat dbgImg(hI, wI, CV_8UC3);
@@ -299,6 +281,20 @@ bool VignetteCalib::preCalib(unsigned long id, float *&image, float *&plane2imgX
299281
}
300282
}
301283

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+
302298
imshow("inRaw", dbgImg);
303299
waitKey(1);
304300

@@ -310,10 +306,27 @@ bool VignetteCalib::preCalib(unsigned long id, float *&image, float *&plane2imgX
310306
}
311307
}
312308

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+
313326
return true;
314327
}
315328

316-
void VignetteCalib::calib()
329+
void VignetteCalib::calib(bool debug)
317330
{
318331
// Create folder for vignette calibration
319332
if (-1 == system("rm -rf vignetteCalibResult"))
@@ -372,7 +385,7 @@ void VignetteCalib::calib()
372385
float *plane2imgX = NULL;
373386
float *plane2imgY = NULL;
374387
float *image = NULL;
375-
if (!preCalib(img, image, plane2imgX, plane2imgY))
388+
if (!preCalib(img, image, plane2imgX, plane2imgY, debug))
376389
{
377390
continue;
378391
}
@@ -413,7 +426,7 @@ void VignetteCalib::calib()
413426
planeColor[pi] = planeColorFC[pi] / planeColorFF[pi];
414427
}
415428
}
416-
if (!_silent)
429+
if (debug)
417430
{
418431
displayImage(planeColor, _gridWidth, _gridWidth, "Plane");
419432
}
@@ -430,7 +443,7 @@ void VignetteCalib::calib()
430443
float *plane2imgX = NULL;
431444
float *plane2imgY = NULL;
432445
float *image = NULL;
433-
if (!preCalib(img, image, plane2imgX, plane2imgY))
446+
if (!preCalib(img, image, plane2imgX, plane2imgY, debug))
434447
{
435448
continue;
436449
}
@@ -562,7 +575,7 @@ void VignetteCalib::calib()
562575
}
563576

564577
// ================================ Store Vignette Image =======================================
565-
if (!_silent)
578+
if (debug)
566579
{
567580
displayImageV(vignetteFactorTT, wI, hI, "VignetteSmoothed");
568581
}
@@ -572,7 +585,7 @@ void VignetteCalib::calib()
572585
imwrite("vignetteCalibResult/vignetteSmoothed.png", wrapSmoothed16);
573586
waitKey(50);
574587

575-
if (!_silent)
588+
if (debug)
576589
{
577590
displayImageV(vignetteFactor, wI, hI, "VignetteOrg");
578591
}
@@ -594,8 +607,10 @@ void VignetteCalib::calib()
594607
delete[] vignetteFactorCT;
595608
}
596609

597-
void VignetteCalib::calibFast()
610+
void VignetteCalib::calibFast(bool debug)
598611
{
612+
std::cout<<"Fast mode! This requires large memory (10GB+)!"<<std::endl;
613+
599614
if (-1 == system("rm -rf vignetteCalibResult"))
600615
{
601616
std::cout << "could not delete old vignetteCalibResult folder!" << std::endl;
@@ -694,22 +709,7 @@ void VignetteCalib::calibFast()
694709

695710
images.push_back(image);
696711

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)
713713
{
714714
// debug-plot.
715715
Mat dbgImg(hI, wI, CV_8UC3);
@@ -764,6 +764,21 @@ void VignetteCalib::calibFast()
764764
}
765765
}
766766

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+
767782
imshow("inRaw", dbgImg);
768783

769784
if (rand() % 40 == 0)
@@ -776,6 +791,24 @@ void VignetteCalib::calibFast()
776791
waitKey(1);
777792
}
778793

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+
779812
p2imgX.push_back(plane2imgX);
780813
p2imgY.push_back(plane2imgY);
781814

@@ -858,7 +891,7 @@ void VignetteCalib::calibFast()
858891
planeColor[pi] = planeColorFC[pi] / planeColorFF[pi];
859892
}
860893
}
861-
if (!_silent)
894+
if (debug)
862895
{
863896
displayImage(planeColor, _gridWidth, _gridWidth, "Plane");
864897
}
@@ -1013,7 +1046,7 @@ void VignetteCalib::calibFast()
10131046
}
10141047

10151048
// ================================ Store Vignette Image =======================================
1016-
if (!_silent)
1049+
if (debug)
10171050
{
10181051
displayImageV(vignetteFactorTT, wI, hI, "VignetteSmoothed");
10191052
}
@@ -1023,7 +1056,7 @@ void VignetteCalib::calibFast()
10231056
imwrite("vignetteCalibResult/vignetteSmoothed.png", wrapSmoothed16);
10241057
waitKey(50);
10251058

1026-
if (!_silent)
1059+
if (debug)
10271060
{
10281061
displayImageV(vignetteFactor, wI, hI, "VignetteOrg");
10291062
}

0 commit comments

Comments
 (0)