-
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
base: 4.x
Are you sure you want to change the base?
Changes from 5 commits
b962353
ef6cebe
d4d89c6
e42de3a
a8cb141
a3cb3d9
b34ec27
5ef6a78
1a94d7e
0456657
de6d4a8
616c25e
b933912
b1ee858
5c04c02
bb415db
80c227d
7c55a71
09b1767
5ff47e5
54d2c93
c077ecc
1bc6800
4d48aee
d787654
345f7fe
a89e952
2473675
2556e8c
a981654
b223312
12d64fe
044bb5e
d0ec626
62f76a4
1cda043
f248779
15ca7a9
78f3e56
7d9de8f
6772932
5a5ed6b
ceb2af6
c1d3f5c
ff2187c
963b29b
3e41953
ff5a312
6e97cc2
16ea96b
d7375e6
9653dde
3763355
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Photometric Calibration | ||
================================================ | ||
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const std::string & There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Vincent, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget license at the top of every file. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use size_t instead of unsigned long There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i==0 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use std::cout There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this member function should be const. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Thanks a lot for your comment! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 |
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!