Skip to content

Commit 5a5ed6b

Browse files
committed
Add debug mode for response calibration.
1 parent 6772932 commit 5a5ed6b

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

modules/photometric_calib/include/opencv2/photometric_calib/ResponseCalib.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CV_EXPORTS ResponseCalib
2525

2626
void plotG(const double *G, const std::string &saveTo);
2727

28-
void calib();
28+
void calib(bool debug);
2929

3030
inline const std::string &getImageFolderPath() const
3131
{

modules/photometric_calib/src/ResponseCalib.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void ResponseCalib::plotG(const double *G, const std::string &saveTo)
121121
{
122122
if (val < k)
123123
{
124-
GImg.at<float>(k, i) = (float) (k - val);
124+
GImg.at<float>(255 - k, i) = (float) (k - val);
125125
}
126126
}
127127
}
@@ -132,14 +132,15 @@ void ResponseCalib::plotG(const double *G, const std::string &saveTo)
132132
std::cout << "Saved: " << saveTo << std::endl;
133133
}
134134

135-
void ResponseCalib::calib()
135+
void ResponseCalib::calib(bool debug)
136136
{
137137
int w = 0, h = 0;
138138
size_t n = 0;
139139

140140
std::vector<double> exposureDurationVec;
141141
std::vector<uchar *> dataVec;
142142

143+
std::cout << "Preprocessing for response calibration... " << std::endl;
143144
for (unsigned long i = 0; i < imageReader->getNumImages(); i += _skipFrames)
144145
{
145146
cv::Mat img = imageReader->getImage(i);
@@ -235,8 +236,11 @@ void ResponseCalib::calib()
235236
logFile.precision(15);
236237

237238
std::cout << "Initial RMSE = " << rmse(G, E, exposureDurationVec, dataVec, w * h)[0] << "!" << std::endl;
238-
plotE(E, w, h, "photoCalibResult/E-0");
239-
cv::waitKey(100);
239+
if (debug)
240+
{
241+
plotE(E, w, h, "photoCalibResult/E-0");
242+
cv::waitKey(100);
243+
}
240244

241245
bool optE = true;
242246
bool optG = true;
@@ -270,9 +274,12 @@ void ResponseCalib::calib()
270274
delete[] GNum;
271275
printf("optG RMSE = %f! \t", rmse(G, E, exposureDurationVec, dataVec, w * h)[0]);
272276

273-
char buf[1000];
274-
snprintf(buf, 1000, "photoCalibResult/G-%02d.png", it + 1);
275-
plotG(G, buf);
277+
if (debug)
278+
{
279+
char buf[1000];
280+
snprintf(buf, 1000, "photoCalibResult/G-%02d.png", it + 1);
281+
plotG(G, buf);
282+
}
276283
}
277284

278285
if (optE)
@@ -302,9 +309,12 @@ void ResponseCalib::calib()
302309
delete[] ESum;
303310
printf("OptE RMSE = %f! \t", rmse(G, E, exposureDurationVec, dataVec, w * h)[0]);
304311

305-
char buf[1000];
306-
snprintf(buf, 1000, "photoCalibResult/E-%02d", it + 1);
307-
plotE(E, w, h, buf);
312+
if (debug)
313+
{
314+
char buf[1000];
315+
snprintf(buf, 1000, "photoCalibResult/E-%02d", it + 1);
316+
plotE(E, w, h, buf);
317+
}
308318
}
309319

310320
// rescale such that maximum response is 255 (fairly arbitrary choice).
@@ -314,9 +324,9 @@ void ResponseCalib::calib()
314324
E[i] *= rescaleFactor;
315325
if (i < 256) G[i] *= rescaleFactor;
316326
}
317-
//Eigen::Vector2d err = rmse(G, E, exposureVec, dataVec, w*h );
327+
318328
Vec2d err = rmse(G, E, exposureDurationVec, dataVec, w * h);
319-
printf("Rescaled RMSE = %f! \trescale with %f!\n", err[0], rescaleFactor);
329+
printf("Rescaled RMSE = %f! \trescale with %f!\n\n", err[0], rescaleFactor);
320330

321331
logFile << it << " " << n << " " << err[1] << " " << err[0] << "\n";
322332

0 commit comments

Comments
 (0)