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 8 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_imgproc opencv_calib3d opencv_features2d 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}
}
34 changes: 34 additions & 0 deletions modules/photometric_calib/include/opencv2/photometric_calib.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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/core.hpp"
#include "opencv2/imgproc.hpp"

#include <vector>
#include <string>
#include <iostream>
#include <fstream>
Copy link
Contributor

Choose a reason for hiding this comment

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

most of those includes are useless in the header and should be in the .cpp

Copy link
Author

Choose a reason for hiding this comment

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

Done.


/** @defgroup photometric_calib Photometric Calibration
*/

namespace cv { namespace photometric_calib{

//! @addtogroup photometric_calib
//! @{

class CV_EXPORTS PhotometricCalibrator : public Algorithm
{
public:
bool validImgs(const std::vector <Mat> &inputImgs, const std::vector<double> &exposureTime);
};

//! @}

}} // namespace photometric_calib, cv

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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/photometric_calib.hpp"

namespace cv { namespace photometric_calib{

//! @addtogroup photometric_calib
//! @{

class Reader
{
public:
Reader(const std::string &folderPath, const std::string &timesPath);

unsigned long getNumImages() const;

double getTimestamp(unsigned long id) const;

float getExposureTime(unsigned long id) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe getExposureDuration would be more explicit ?

Copy link
Author

Choose a reason for hiding this comment

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

Done.



private:
inline void loadTimestamps(const std::string &timesFile);

std::vector<String> files;
std::vector<double> timeStamps;
Copy link
Contributor

Choose a reason for hiding this comment

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

the format should be explained in the doc: what is that double ? Time since when ?

Copy link
Author

Choose a reason for hiding this comment

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

Hi Vincent,
Thanks for your comment.
doc means doxygen or?

Copy link
Author

Choose a reason for hiding this comment

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

And I thought timestamps always means the Unix Timestamp since Jan 01 1970?

std::vector<float> exposureTimes;

int width, height;

String path;
};

//! @}

}} // namespace cv photometric_calib
#endif //_OPENCV_READER_HPP
83 changes: 83 additions & 0 deletions modules/photometric_calib/src/Reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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.

#include "precomp.hpp"
#include "opencv2/photometric_calib/Reader.hpp"

namespace cv { namespace photometric_calib{

unsigned long Reader::getNumImages() const
{
return (unsigned long)files.size();
}

void Reader::loadTimestamps(const std::string &timesFile)
{
CV_Assert(timesFile.substr(timesFile.find_last_of(".") + 1) == "yaml" || timesFile.substr(timesFile.find_last_of(".") + 1) == "yml");

FileStorage timeFile;
timeFile.open(timesFile, FileStorage::READ);
timeStamps.clear();
exposureTimes.clear();

CV_Assert(timeFile.isOpened());

FileNode timeStampNode = timeFile["times"];
FileNode exposureTimeNode = timeFile["exposures"];

CV_Assert(timeStampNode.type() == FileNode::SEQ && exposureTimeNode.type() == FileNode::SEQ);

FileNodeIterator itTs = timeStampNode.begin(), itTsEnd = timeStampNode.end();
FileNodeIterator itEt = exposureTimeNode.begin(), itEtEnd = exposureTimeNode.end();

for (; itTs != itTsEnd; ++itTs)
timeStamps.push_back((double)*itTs);
for (; itEt != itEtEnd; ++itEt)
exposureTimes.push_back((float)*itEt);

timeFile.release();

CV_Assert(timeStamps.size() == getNumImages() && exposureTimes.size() == getNumImages());
}

Reader::Reader(const std::string &folderPath, const std::string &timesPath)
{
String cvFolderPath(folderPath);
glob(cvFolderPath, files);
CV_Assert(files.size() > 0);
std::sort(files.begin(), files.end());
loadTimestamps(timesPath);

width = 0;
height = 0;

for(size_t i = 0; i < files.size(); ++i)
{
Mat img = imread(files[i]);
CV_Assert(img.type() == CV_8U);
if(i == 0)
{
width = img.cols;
height = img.rows;
}
else
{
CV_Assert(width == img.cols && height == img.rows);
}
}
}

double Reader::getTimestamp(unsigned long id) const
{
CV_Assert(id < timeStamps.size());
return timeStamps[id];
}

float Reader::getExposureTime(unsigned long id) const
{
CV_Assert(id < exposureTimes.size());
return exposureTimes[id];
}

}} // namespace photometric_calib, cv
43 changes: 43 additions & 0 deletions modules/photometric_calib/src/photometric_calib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.

#include "precomp.hpp"
#include "opencv2/photometric_calib.hpp"

namespace cv{ namespace photometric_calib{

using namespace std;

bool PhotometricCalibrator::validImgs(const std::vector <Mat> &inputImgs, const std::vector<double> &exposureTime)
{
if(inputImgs.empty() || exposureTime.empty() || inputImgs.size() != exposureTime.size())
return false;

int width = 0, height = 0;
for(size_t i = 0; i < inputImgs.size(); ++ i)
{
Mat img;
img = inputImgs[i];
if(img.type() != CV_8U)
{
cout<<"The type of the image should be CV_8U!"<<endl;
return false;
}
if((width!=0 && width != img.cols) || img.cols==0)
{
cout<<"Width mismatch!"<<endl;
return false;
};
if((height!=0 && height != img.rows) || img.rows==0)
{
cout<<"Height mismatch!"<<endl;
return false;
};
width = img.cols;
height = img.rows;
}
return true;
}

}} // namespace photometric_calib, cv
12 changes: 12 additions & 0 deletions modules/photometric_calib/src/precomp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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_PRECOMP_H__
#define __OPENCV_PRECOMP_H__

#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <vector>
#endif