-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[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
nynyg
wants to merge
53
commits into
opencv:4.x
Choose a base branch
from
nynyg:photometric-calibration
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
ef6cebe
Add initialization of variables and delete empty line.
d4d89c6
add Reader class to read the imgaes used for photometric calibration
nynyg e42de3a
fix quotes, space and guards: https://github.com/opencv/opencv_contri…
nynyg a8cb141
change the module name to photometric_calib
nynyg a3cb3d9
Add brief README.md
nynyg b34ec27
Add .bib file.
nynyg 5ef6a78
Fixed problems commented by @vrabaud
nynyg 1a94d7e
change exposureTime to exposureDuration.
nynyg 0456657
Delete useless included header files
nynyg de6d4a8
changed some properties names and added some getters and setters
nynyg 616c25e
add Doxygen documentation
nynyg b933912
Add CV_EXPORTS to Reader class.
nynyg b1ee858
Read image with IMREAD_GRAYSCALE and add getImage() method
nynyg 5c04c02
Camera response function(Gamma function) remover.
nynyg bb415db
fix cast type.
nynyg 80c227d
fix Variable Length Array for MSVS.
nynyg 7c55a71
nullptr -> 0
nynyg 09b1767
Change method name from *Arr to *Vec
nynyg 5ff47e5
Add class VignetteRemover
nynyg 54d2c93
Specifying image format when reading images from a folder.
nynyg c077ecc
Small modifications. Add new member property and method to Reader class.
nynyg 1bc6800
Add class ResponseCalib: draft of camera response function calibrator.
nynyg 4d48aee
fix shadow declaration.
nynyg d787654
add math.h header file.
nynyg 345f7fe
Android doesn't support long double, so use sqrt instead of sqrtl. Ac…
nynyg a89e952
fix type conversion problem.
nynyg 2473675
Create class VignetteCalib
nynyg 2556e8c
add support header files for camera undistortion and aruco marker det…
nynyg a981654
finish interfaces of VignetteCalib class
nynyg b223312
finish implementation of VignetteCalibration roughly. Still a lot to …
nynyg 12d64fe
Use proper module and remove redundant headers.
nynyg 044bb5e
Fix some bugs.
nynyg d0ec626
Fix warnings on Win and Android
nynyg 62f76a4
Delete useless code and clean up header files.
nynyg 1cda043
Add useful std output for response calibration.
nynyg f248779
Add doxygen to GammaRemover and VignetteRemover.
nynyg 15ca7a9
Add imageFormat parameter for response and vignetting calibration con…
nynyg 78f3e56
Memory-efficient vignette calibration implementation.
nynyg 7d9de8f
Code reformat.
nynyg 6772932
Time-efficient vignette calibration implementation.
nynyg 5a5ed6b
Add debug mode for response calibration.
nynyg ceb2af6
Add sample code for response calibration.
nynyg c1d3f5c
Better visualization for the sample code of response calibration.
nynyg ff2187c
Change parameter bool silent of the constructor to the parameter of m…
nynyg 963b29b
Fix bug of calibFast().
nynyg 3e41953
More convenient VignetteRemover.
nynyg ff5a312
Sample code of vignette calibration.
nynyg 6e97cc2
Fix bug with header files of sample codes
nynyg 16ea96b
Update Doxygen.
nynyg d7375e6
Add test header file
nynyg 9653dde
Add documentation.
nynyg 3763355
Add test main
nynyg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Photometric Calibration | ||
================================================ | ||
|
||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
modules/photometric_calib/include/opencv2/photometric_calib.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
80 changes: 80 additions & 0 deletions
80
modules/photometric_calib/include/opencv2/photometric_calib/GammaRemover.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
99 changes: 99 additions & 0 deletions
99
modules/photometric_calib/include/opencv2/photometric_calib/Reader.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ×Path); | ||
|
||
/*! | ||
* @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 ×File); | ||
|
||
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 |
52 changes: 52 additions & 0 deletions
52
modules/photometric_calib/include/opencv2/photometric_calib/ResponseCalib.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
73 changes: 73 additions & 0 deletions
73
modules/photometric_calib/include/opencv2/photometric_calib/VignetteCalib.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the documentation ?
There was a problem hiding this comment.
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!