Skip to content

Commit ff5a312

Browse files
committed
Sample code of vignette calibration.
1 parent 3e41953 commit ff5a312

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <string>
2+
#include <iostream>
3+
#include <iomanip>
4+
#include <vector>
5+
6+
#include "opencv2/opencv.hpp"
7+
#include "opencv2/core.hpp"
8+
#include "opencv2/highgui.hpp"
9+
#include "opencv2/photometric_calib.hpp"
10+
#include "opencv2/imgproc/imgproc.hpp"
11+
12+
using namespace std;
13+
using namespace cv;
14+
15+
int main(int argc, char** argv)
16+
{
17+
// Please down load the sample dataset from:
18+
// https://www.dropbox.com/s/5x48uhc7k2bgjcj/GSoC2017_PhotometricCalib_Sample_Data.zip?dl=0
19+
// By unzipping the file, you would get a folder named /GSoC2017_PhotometricCalib_Sample_Data which contains 2 subfolders:
20+
// response_calib, vignette_calib
21+
// in this sample, we will use the data in the folder vignette_calib
22+
23+
// Prefix for the data, e.g. /Users/Yelen/GSoC2017_PhotometricCalib_Sample
24+
string userPrefix = "/Users/Yelen/GSoC2017_PhotometricCalib_Sample_Data/";
25+
// The path for the images used for response calibration
26+
string imageFolderPath = userPrefix + "vignette_calib/images";
27+
// The yaml file which contains the timestamps and exposure times for each image used for vignette calibration
28+
string timePath = userPrefix + "vignette_calib/times.yaml";
29+
// The yaml file which contains the camera intrinsics and extrinsics.
30+
// Note that the images are already rectified, so the distortion parameters are 0s
31+
string cameraPath = userPrefix + "vignette_calib/camera.yaml";
32+
// The pcalib file. Vignette calibration can be performed only when provided with pcalib file.
33+
// We use the identical pcalib.yaml file generated by response_calibration.cpp
34+
// You can refer to the code in response_calibration.cpp for details
35+
string gammaPath = userPrefix + "vignette_calib/pcalib.yaml";
36+
37+
// Construct a photometric_calib::VignetteCalib object by giving path of image, path of time file, camera parameter file, pcalib file and specify the format of images
38+
photometric_calib::VignetteCalib vigCal(imageFolderPath, timePath, cameraPath, gammaPath, "jpg");
39+
40+
// Debug mode will visualize the optimization process and generate some temporary data
41+
bool debug = true;
42+
// Calibration of camera response function begins
43+
vigCal.calib(debug);
44+
45+
// You can also use fast mode, but with much memory (potentially with 10GB+)
46+
// vigCal.calibFast(debug);
47+
48+
// The result and some intermediate data are stored in the folder ./vignetteCalibResult in which
49+
// vignette.png and vignetteSmoothed.png are the vignette images.
50+
// In practice, vignetteSomoothed.png is used, since it doesn't have the black boarders.
51+
Mat vigSmoothed = imread("./vignetteCalibResult/vignetteSmoothed.png", CV_LOAD_IMAGE_UNCHANGED);
52+
// As shown as Fig.4 in the paper from J.Engel, et al. in the paper A Photometrically Calibrated Benchmark For Monocular Visual Odometry
53+
namedWindow( "Vignette Smoothed", WINDOW_AUTOSIZE );
54+
imshow("Vignette Smoothed", vigSmoothed);
55+
56+
// To see the vignette-calibrated image, we can use VignetteRemover
57+
Mat oriImg = imread(imageFolderPath + "/00480.jpg", CV_LOAD_IMAGE_UNCHANGED);
58+
photometric_calib::GammaRemover gammaRemover(gammaPath, oriImg.cols, oriImg.rows);
59+
photometric_calib::VignetteRemover vignetteRemover("./vignetteCalibResult/vignetteSmoothed.png", gammaPath, oriImg.cols, oriImg.rows);
60+
Mat resCaliImg = gammaRemover.getUnGammaImageMat(oriImg);
61+
Mat vigCaliImg = vignetteRemover.getUnVignetteImageMat(oriImg);
62+
63+
// Visualization
64+
namedWindow( "Original Image", WINDOW_AUTOSIZE );
65+
imshow("Original Image", oriImg);
66+
namedWindow( "Gamma Removed Image", WINDOW_AUTOSIZE );
67+
imshow("Gamma Removed Image", resCaliImg);
68+
namedWindow( "Vignette Removed Image", WINDOW_AUTOSIZE );
69+
imshow("Vignette Removed Image", vigCaliImg);
70+
71+
waitKey(0);
72+
73+
return 0;
74+
}

0 commit comments

Comments
 (0)