Skip to content

[GSoC 2017]Photometric Calibration. #1219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 53 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b962353
first commit. Added photometric calibration class and a dummy function
Jun 10, 2017
ef6cebe
Add initialization of variables and delete empty line.
Jun 12, 2017
d4d89c6
add Reader class to read the imgaes used for photometric calibration
nynyg Jun 20, 2017
e42de3a
fix quotes, space and guards: https://github.com/opencv/opencv_contri…
nynyg Jun 21, 2017
a8cb141
change the module name to photometric_calib
nynyg Jun 21, 2017
a3cb3d9
Add brief README.md
nynyg Jun 26, 2017
b34ec27
Add .bib file.
nynyg Jun 26, 2017
5ef6a78
Fixed problems commented by @vrabaud
nynyg Jun 26, 2017
1a94d7e
change exposureTime to exposureDuration.
nynyg Jun 29, 2017
0456657
Delete useless included header files
nynyg Jun 30, 2017
de6d4a8
changed some properties names and added some getters and setters
nynyg Jun 30, 2017
616c25e
add Doxygen documentation
nynyg Jun 30, 2017
b933912
Add CV_EXPORTS to Reader class.
nynyg Jun 30, 2017
b1ee858
Read image with IMREAD_GRAYSCALE and add getImage() method
nynyg Jul 3, 2017
5c04c02
Camera response function(Gamma function) remover.
nynyg Jul 3, 2017
bb415db
fix cast type.
nynyg Jul 3, 2017
80c227d
fix Variable Length Array for MSVS.
nynyg Jul 3, 2017
7c55a71
nullptr -> 0
nynyg Jul 4, 2017
09b1767
Change method name from *Arr to *Vec
nynyg Jul 4, 2017
5ff47e5
Add class VignetteRemover
nynyg Jul 4, 2017
54d2c93
Specifying image format when reading images from a folder.
nynyg Jul 10, 2017
c077ecc
Small modifications. Add new member property and method to Reader class.
nynyg Jul 12, 2017
1bc6800
Add class ResponseCalib: draft of camera response function calibrator.
nynyg Jul 12, 2017
4d48aee
fix shadow declaration.
nynyg Jul 12, 2017
d787654
add math.h header file.
nynyg Jul 12, 2017
345f7fe
Android doesn't support long double, so use sqrt instead of sqrtl. Ac…
nynyg Jul 12, 2017
a89e952
fix type conversion problem.
nynyg Jul 12, 2017
2473675
Create class VignetteCalib
nynyg Jul 18, 2017
2556e8c
add support header files for camera undistortion and aruco marker det…
nynyg Jul 30, 2017
a981654
finish interfaces of VignetteCalib class
nynyg Jul 30, 2017
b223312
finish implementation of VignetteCalibration roughly. Still a lot to …
nynyg Jul 30, 2017
12d64fe
Use proper module and remove redundant headers.
nynyg Aug 9, 2017
044bb5e
Fix some bugs.
nynyg Aug 9, 2017
d0ec626
Fix warnings on Win and Android
nynyg Aug 9, 2017
62f76a4
Delete useless code and clean up header files.
nynyg Aug 16, 2017
1cda043
Add useful std output for response calibration.
nynyg Aug 16, 2017
f248779
Add doxygen to GammaRemover and VignetteRemover.
nynyg Aug 16, 2017
15ca7a9
Add imageFormat parameter for response and vignetting calibration con…
nynyg Aug 20, 2017
78f3e56
Memory-efficient vignette calibration implementation.
nynyg Aug 20, 2017
7d9de8f
Code reformat.
nynyg Aug 20, 2017
6772932
Time-efficient vignette calibration implementation.
nynyg Aug 20, 2017
5a5ed6b
Add debug mode for response calibration.
nynyg Aug 21, 2017
ceb2af6
Add sample code for response calibration.
nynyg Aug 21, 2017
c1d3f5c
Better visualization for the sample code of response calibration.
nynyg Aug 21, 2017
ff2187c
Change parameter bool silent of the constructor to the parameter of m…
nynyg Aug 21, 2017
963b29b
Fix bug of calibFast().
nynyg Aug 21, 2017
3e41953
More convenient VignetteRemover.
nynyg Aug 21, 2017
ff5a312
Sample code of vignette calibration.
nynyg Aug 21, 2017
6e97cc2
Fix bug with header files of sample codes
nynyg Aug 21, 2017
16ea96b
Update Doxygen.
nynyg Aug 21, 2017
d7375e6
Add test header file
nynyg Aug 28, 2017
9653dde
Add documentation.
nynyg Aug 28, 2017
3763355
Add test main
nynyg Aug 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/photometric_calib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(the_description "Photometric Calibration")
ocv_define_module(photometric_calib opencv_core opencv_aruco opencv_calib3d opencv_highgui WRAP python)
8 changes: 8 additions & 0 deletions modules/photometric_calib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Photometric Calibration
================================================
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the documentation ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Thanks a lot for your comment!


Implementation of non-parametric photometric calibration algorithm proposed by J. Engel et al.:

1. Camera Response Function Calibration
2. Vignette Calibration
3. Photometric Distortion Remover
9 changes: 9 additions & 0 deletions modules/photometric_calib/doc/photometric_calib.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@InProceedings{engel2016monodataset,
author = "J. Engel and V. Usenko and D. Cremers",
title = "A Photometrically Calibrated Benchmark For Monocular Visual Odometry",
booktitle = "arXiv:1607.02555",
arXiv = " arXiv:1607.02555",
year = "2016",
month = "July",
keywords={mono-ds,dso}
}
28 changes: 28 additions & 0 deletions modules/photometric_calib/include/opencv2/photometric_calib.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#ifndef __OPENCV_PHOTOMETRIC_CALIB_HPP__
#define __OPENCV_PHOTOMETRIC_CALIB_HPP__

#include "opencv2/photometric_calib/Reader.hpp"
#include "opencv2/photometric_calib/GammaRemover.hpp"
#include "opencv2/photometric_calib/VignetteRemover.hpp"
#include "opencv2/photometric_calib/ResponseCalib.hpp"
#include "opencv2/photometric_calib/VignetteCalib.hpp"

/**
* @defgroup photometric_calib Photometric Calibration
* The photometric_calib contains photomeric calibration algorithm proposed by Jakob Engel. \n
* The implementation is totally based on the paper \cite engel2016monodataset. \n
* Photometric calibration aimed at removing the camera response function and vitnetting artefact,
* by which the tracking and image alignment algorithms based on direct methods can be improved significantly. \n
* For details please refer to \cite engel2016monodataset.
*/

namespace cv {
namespace photometric_calib {
} // namespace photometric_calib
} // namespace cv

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#ifndef _OPENCV_GAMMAREMOVER_HPP
#define _OPENCV_GAMMAREMOVER_HPP

#include "opencv2/core.hpp"

namespace cv {
namespace photometric_calib {

//! @addtogroup photometric_calib
//! @{

/*!
* @brief Class for removing the camera response function (mostly gamma function) when provided with pcalib file.
*
*/

class CV_EXPORTS GammaRemover
{
public:
/*!
* @brief Constructor
* @param gammaPath the path of pcalib file of which the format should be .yaml or .yml
* @param w_ the width of input image
* @param h_ the height of input image
*/
GammaRemover(const std::string &gammaPath, int w_, int h_);

/*!
* @brief get irradiance image in the form of cv::Mat. Convenient for display, etc.
* @param inputIm
* @return
*/
Mat getUnGammaImageMat(Mat inputIm);

/*!
* @brief get irradiance image in the form of std::vector<float>. Convenient for optimization or SLAM.
* @param inputIm
* @param outImVec
*/
void getUnGammaImageVec(Mat inputIm, std::vector<float> &outImVec);

/*!
* @brief get gamma function.
* @return
*/
inline float *getG()
{
if (!validGamma)
{ return 0; }
else
{ return G; }
};

/*!
* @brief get inverse gamma function
* @return
*/
inline float *getGInv()
{
if (!validGamma)
{ return 0; }
else
{ return GInv; }
};

private:
float G[256];
float GInv[256];
int w, h;
bool validGamma;
};

} // namespace photometric_calib
} // namespace cv

#endif //_OPENCV__GAMMAREMOVER_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#ifndef _OPENCV_READER_HPP
#define _OPENCV_READER_HPP

#include "opencv2/core.hpp"

#include <vector>
#include <string>

namespace cv {
namespace photometric_calib {

//! @addtogroup photometric_calib
//! @{

/*!
* @brief Class for reading the sequence used for photometric calibration. Both the folder path of the sequence
* and the path of time file should be provided. The images of the sequence should be of format CV_8U. The time
* file should be .yaml or .yml. In the time file, the timestamps and exposure duration of the corresponding images
* of the sequence should be provided.
*
* The image paths are stored in std::vector<String> images, timestamps are stored in std::vector<double> timeStamps,
* exposure duration is stored in std::vector<float> exposureTimes
*/

class CV_EXPORTS Reader
{
public:
/*!
* @brief Constructor
* @param folderPath the path of folder which contains the images
* @param imageExt the format of the input images, e.g., jpg or png.
* @param timesPath the path of time file
*/
Reader(const std::string &folderPath, const std::string &imageExt, const std::string &timesPath);

/*!
* @return the amount of images loaded
*/
unsigned long getNumImages() const;


/*!
* @brief Given the id of the image and return the image. id is in fact just the index of the image in the
* vector contains all the images.
* @param id
* @return Mat of the id^th image.
*/
Mat getImage(unsigned long id) const;

/*!
* @brief Given the id of the image and return its timestamp value. id is in fact just the index of the image in the
* vector contains all the images.
* @param id
* @return timestamp of the id^th image.
*/
double getTimestamp(unsigned long id) const;

/*!
* @brief Given the id of the image and return its exposure duration when is was taken.
* @param id
* @return exposure duration of the image.
*/
float getExposureDuration(unsigned long id) const;

int getWidth() const;

int getHeight() const;

const std::string &getFolderPath() const;

const std::string &getTimeFilePath() const;

private:
/*!
* @brief Load timestamps and exposure duration.
* @param timesFile
*/
inline void loadTimestamps(const std::string &timesFile);

std::vector<String> images; //All the names/paths of images
std::vector<double> timeStamps; //All the Unix Time Stamps of images
std::vector<float> exposureDurations;//All the exposure duration for images

int _width, _height;//The image width and height. All the images should be of the same size.

std::string _folderPath;
std::string _timeFilePath;
};

//! @}

} // namespace photometric_calib
} // namespace cv

#endif //_OPENCV_READER_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#ifndef _OPENCV_RESPONSECALIB_HPP
#define _OPENCV_RESPONSECALIB_HPP

#include "opencv2/photometric_calib/Reader.hpp"

namespace cv {
namespace photometric_calib {

class CV_EXPORTS ResponseCalib
{
public:
ResponseCalib(std::string folderPath, std::string timePath, std::string imageFormat);

ResponseCalib(std::string folderPath, std::string timePath, int leakPadding, int nIts, int skipFrames,
std::string imageFormat);

void plotE(const double *E, int w, int h, const std::string &saveTo);

Vec2d rmse(const double *G, const double *E, const std::vector<double> &exposureVec,
const std::vector<unsigned char *> &dataVec, int wh);

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

void calib(bool debug);

inline const std::string &getImageFolderPath() const
{
CV_Assert(imageReader);
return imageReader->getFolderPath();
}

inline const std::string &getTimeFilePath() const
{
CV_Assert(imageReader);
return imageReader->getTimeFilePath();
}

private:
int _leakPadding;
int _nIts;
int _skipFrames;
Reader *imageReader;
};

} // namespace photometric_calib
} // namespace cv

#endif //_OPENCV_RESPONSECALIB_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#ifndef _OPENCV_VIGNETTECALIB_HPP
#define _OPENCV_VIGNETTECALIB_HPP

#include "opencv2/core.hpp"
#include "opencv2/photometric_calib/Reader.hpp"
#include "opencv2/photometric_calib/GammaRemover.hpp"

namespace cv {
namespace photometric_calib {


class CV_EXPORTS VignetteCalib
{
public:
VignetteCalib(std::string folderPath, std::string timePath, std::string cameraFile, std::string gammaFile,
std::string imageFormat);

VignetteCalib(std::string folderPath, std::string timePath, std::string cameraFile, std::string gammaFile,
std::string imageFormat, int imageSkip, int maxIterations, int outlierTh,
int gridWidth, int gridHeight, float facW, float facH, int maxAbsGrad);

virtual ~VignetteCalib();

//EIGEN_ALWAYS_INLINE float getInterpolatedElement(const float* const mat, const float x, const float y, const int width)
float getInterpolatedElement(const float *const mat, const float x, const float y, const int width);

float calMeanExposureTime();

void displayImage(float *I, int w, int h, std::string name);

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

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

void calib(bool debug);

void calibFast(bool debug);

private:
int _imageSkip;
int _maxIterations;
int _outlierTh;

// grid width for template image.
int _gridWidth;
int _gridHeight;

// width of grid relative to marker (fac times marker size)
float _facW;
float _facH;

// remove pixel with absolute gradient larger than this from the optimization.
int _maxAbsGrad;

Mat _cameraMatrix;
Mat _distCoeffs;
Matx33f _K_p2idx;
Matx33f _K_p2idx_inverse;

Reader *imageReader;
GammaRemover *gammaRemover;

float _meanExposure;
};

} // namespace photometric_calib
} // namespace cv

#endif //_OPENCV_VIGNETTECALIB_HPP
Loading