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 5 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)
2 changes: 2 additions & 0 deletions modules/photometric_calib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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!

68 changes: 68 additions & 0 deletions modules/photometric_calib/include/opencv2/photometric_calib.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2014, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#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.


namespace cv { namespace photometric_calib{

//! @addtogroup photometric_calib
//! @{

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

Choose a reason for hiding this comment

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

don't use tabs for indentation. Arguments should be const if they are const.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

Thanks a lot for your comment!

};

//! @}

}} // namespace photometric_calib, cv

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _OPENCV_READER_HPP
#define _OPENCV_READER_HPP

#include "opencv2/photometric_calib.hpp"

namespace cv { namespace photometric_calib{

class Reader
{
public:
Reader(std::string folderPath, std::string timesPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

const std::string &

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

Thanks a lot for your comment!


unsigned long getNumImages();

double getTimestamp(unsigned long id);

float getExposureTime(unsigned long id);


private:
inline void loadTimestamps(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
81 changes: 81 additions & 0 deletions modules/photometric_calib/src/Reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget license at the top of every file.

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,

I think there is a shorter version (basically a link to http://opencv.org/license.html) and the complete OpenCV's license, which one should I use?

// Created by Nan Yang on 17/6/14.
//

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

namespace cv { namespace photometric_calib{

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

void Reader::loadTimestamps(std::string timesFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the format of that file ? You should use OpenCV serialization for whatever you do.

{
std::ifstream timesStream;
timesStream.open(timesFile.c_str());
timeStamps.clear();
exposureTimes.clear();
while (!timesStream.eof() && timesStream.good())
{
char buf[1000];
timesStream.getline(buf, 1000);

int id = 0;
double timeStamp = 0.0;
float exposureTime = 0.0;

CV_Assert(3 == scanf(buf, "%d %lf %f", &id, &timeStamp, &exposureTime));

timeStamps.push_back(timeStamp);
exposureTimes.push_back(exposureTime);
}
timesStream.close();

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

Reader::Reader(std::string folderPath, 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(unsigned long i = 0; i < files.size(); ++i)
Copy link
Contributor

Choose a reason for hiding this comment

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

use size_t instead of unsigned long

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,

Should I also change

unsigned long getNumImages() const;
double getTimestamp(unsigned long id) const;
float getExposureTime(unsigned long id) const;

to

size_t getNumImages() const;
double getTimestamp(size_t id) const;
float getExposureTime(size_t id) const;

{
Mat img = imread(files[i]);
CV_Assert(img.type() == CV_8U);
if(0 == i)
Copy link
Contributor

Choose a reason for hiding this comment

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

i==0

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

Thanks a lot for your comment!

{
width = img.cols;
height = img.rows;
}
else
{
CV_Assert(width == img.cols && height == img.rows);
}
}

std::cout<<getNumImages()<<" imgases from"<<folderPath<<" loaded successfully!"<<std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use std::cout
Plus there is a typo: images.

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 a lot for your comments!

Can I use std::cerr to output some error info?

}

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

float Reader::getExposureTime(unsigned long id)
Copy link
Contributor

Choose a reason for hiding this comment

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

this member function should be const.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

Thanks a lot for your comment!

Copy link
Author

Choose a reason for hiding this comment

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

I made 3 functions const:

unsigned long getNumImages() const;
double getTimestamp(unsigned long id) const; 
float getExposureTime(unsigned long id) const;

{
CV_Assert(id < exposureTimes.size());
return exposureTimes[id];
}

}} // namespace photometric_calib, cv
80 changes: 80 additions & 0 deletions modules/photometric_calib/src/photometric_calib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2014, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

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

namespace cv{ namespace photometric_calib{

using namespace std;

bool PhotometricCalibrator::validImgs(std::vector <Mat> &inputImgs, 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
50 changes: 50 additions & 0 deletions modules/photometric_calib/src/precomp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef __OPENCV_PRECOMP_H__
#define __OPENCV_PRECOMP_H__

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