Skip to content

Commit 2db5273

Browse files
committed
add Reader class to read the imgaes used for photometric calibration
1 parent ef6cebe commit 2db5273

File tree

4 files changed

+117
-5
lines changed

4 files changed

+117
-5
lines changed

modules/pcalib/include/opencv2/pcalib.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#include <opencv2/imgproc.hpp>
4848

4949
#include <vector>
50+
#include <string>
51+
#include <iostream>
52+
#include <fstream>
5053

5154
namespace cv{ namespace pcalib{
5255

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef _OPENCV_READER_HPP
2+
#define _OPENCV_READER_HPP
3+
4+
#include "opencv2/pcalib.hpp"
5+
6+
namespace cv { namespace pcalib{
7+
8+
class Reader
9+
{
10+
public:
11+
Reader(std::string folderPath, std::string timesPath);
12+
13+
unsigned long getNumImages();
14+
15+
double getTimestamp(unsigned long id);
16+
17+
float getExposureTime(unsigned long id);
18+
19+
20+
private:
21+
inline void loadTimestamps(std::string timesFile);
22+
23+
std::vector<String> files;
24+
std::vector<double> timeStamps;
25+
std::vector<float> exposureTimes;
26+
27+
int width, height;
28+
29+
String path;
30+
};
31+
32+
}} // namespace cv pcalib
33+
#endif //_OPENCV_READER_HPP

modules/pcalib/src/Reader.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// Created by 杨楠 on 17/6/14.
3+
//
4+
5+
#include "opencv2/pcalib/Reader.hpp"
6+
#include "precomp.hpp"
7+
8+
namespace cv{ namespace pcalib{
9+
10+
unsigned long Reader::getNumImages()
11+
{
12+
return files.size();
13+
}
14+
15+
void Reader::loadTimestamps(std::string timesFile)
16+
{
17+
std::ifstream timesStream;
18+
timesStream.open(timesFile);
19+
timeStamps.clear();
20+
exposureTimes.clear();
21+
while (!timesStream.eof() && timesStream.good())
22+
{
23+
char buf[1000];
24+
timesStream.getline(buf, 1000);
25+
26+
int id = 0;
27+
double timeStamp = 0.0;
28+
float exposureTime = 0.0;
29+
30+
CV_Assert(3 == scanf(buf, "%d %lf %f", &id, &timeStamp, &exposureTime));
31+
32+
timeStamps.push_back(timeStamp);
33+
exposureTimes.push_back(exposureTime);
34+
}
35+
timesStream.close();
36+
37+
CV_Assert(timeStamps.size() == getNumImages() && exposureTimes.size() == getNumImages());
38+
}
39+
40+
Reader::Reader(std::string folderPath, std::string timesPath)
41+
{
42+
String cvFolderPath(folderPath);
43+
glob(cvFolderPath, files);
44+
CV_Assert(files.size() > 0);
45+
std::sort(files.begin(), files.end());
46+
loadTimestamps(timesPath);
47+
48+
width = 0;
49+
height = 0;
50+
51+
for(unsigned long i = 0; i < files.size(); ++i)
52+
{
53+
Mat img = imread(files[i]);
54+
CV_Assert(img.type() == CV_8U);
55+
if(0 == i)
56+
{
57+
width = img.cols;
58+
height = img.rows;
59+
}
60+
else
61+
{
62+
CV_Assert(width == img.cols && height == img.rows);
63+
}
64+
}
65+
66+
std::cout<<getNumImages()<<" imgases from"<<folderPath<<" loaded successfully!"<<std::endl;
67+
}
68+
69+
double Reader::getTimestamp(unsigned long id)
70+
{
71+
CV_Assert(id >= 0 && id < timeStamps.size());
72+
return timeStamps[id];
73+
}
74+
75+
float Reader::getExposureTime(unsigned long id)
76+
{
77+
CV_Assert(id >= 0 && id < exposureTimes.size());
78+
return exposureTimes[id];
79+
}
80+
81+
}}

modules/pcalib/src/pcalib.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@
4646
#include "precomp.hpp"
4747
#include "opencv2/pcalib.hpp"
4848

49-
#include <opencv2/core.hpp>
50-
51-
#include <vector>
52-
#include <iostream>
53-
5449
namespace cv{ namespace pcalib{
5550

5651
using namespace std;

0 commit comments

Comments
 (0)