-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageData.h
216 lines (174 loc) · 5.31 KB
/
ImageData.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// =========================================================================================
// Structured Class-Label in Random Forests. This is a re-implementation of
// the work we presented at ICCV'11 in Barcelona, Spain.
//
// In case of using this code, please cite the following paper:
// P. Kontschieder, S. Rota Bulo', H. Bischof and M. Pelillo.
// Structured Class-Labels in Random Forests for Semantic Image Labelling. In (ICCV), 2011.
//
// Implementation by Peter Kontschieder and Samuel Rota Bulo'
//
// Parts of the code (for data representation) in this file use the publicly available code of
// http://www.vision.ee.ethz.ch/~gallju/projects/houghforest/
// J. Gall and V. Lempitsky: Class-Specific Hough Forests for Object Detection. In (CVPR), 2009.
//
// and the Sigma Points code of Kluckner et al.
// http://www.icg.tugraz.at/Members/kluckner/files/CovSigmaPointsComp.zip
// S. Kluckner, T. Mauthner, P.M. Roth and H. Bischof. Semantic Classification in Aerial
// Imagery by Integrating Appearance and Height Information. In (ACCV), 2009.
//
//
// October 2013
//
// =========================================================================================
#ifndef IMAGEDATA_H_
#define IMAGEDATA_H_
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <sys/stat.h>
#include <opencv2/core/core.hpp>
#include <opencv2/core/core_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "ConfigReader.h"
#include "IntegralStructures.h"
#define USE_CORR_COEFF 1
using namespace std;
namespace vision
{
class HoG
{
public:
HoG();
~HoG()
{
cvReleaseMat(&Gauss);
delete ptGauss;
}
void extractOBin(cv::Mat Iorient, cv::Mat Imagn, vector<cv::Mat> &out, int off);
private:
void calcHoGBin(uchar* ptOrient, uchar* ptMagn, int step, double* desc);
void binning(float v, float w, double* desc, int maxb);
int bins;
float binsize;
int g_w;
CvMat* Gauss;
// Gauss as vector
float* ptGauss;
};
static HoG hog;
class ImageData
{
// Types
protected:
typedef struct
{
bool bLoaded;
string strInputImage;
string strFeatureImagesPath;
string strFeatureImagesIntegralPath;
string strLabelImagePath;
vector<cv::Mat> vectFeatures;
vector<cv::Mat> vectFeaturesIntegral;
cv::Mat imgLabel;
} CImageCacheElement;
// Member variables
protected:
vector<CImageCacheElement> vectImageData;
string strFormat;
int iFirstFrame;
int iNbFeatures;
int iWidth, iHeight;
int iNbFps;
list<unsigned int> listIndicesImagesLastLoaded;
bool bUseIntegralImages;
public:
bool bGenerateFeatures;
unsigned int iNbMaxImagesLoaded;
// Member functions
public:
ImageData()
{
iNbMaxImagesLoaded = 100;
bUseIntegralImages = true;
bGenerateFeatures = false;
}
virtual bool setConfiguration(ConfigReader &);
~ImageData()
{
}
virtual size_t getNbImages() const
{
return vectImageData.size();
}
virtual int getNbFeatures() const
{
return iNbFeatures;
}
virtual int getWidth() const
{
return iWidth;
}
virtual int getHeight() const
{
return iHeight;
}
virtual vector<cv::Mat> *getFeatureImages(unsigned int);
virtual vector<cv::Mat> *getFeatureIntegralImages(unsigned int);
virtual cv::Mat *getLabelImage(unsigned int);
virtual string getInputImageName(unsigned int);
virtual void getGradients(const cv::Mat, vector<cv::Mat>&) const;
virtual cv::Mat matchHistograms(const cv::Mat, const cv::Mat) const;
virtual bool UseIntegralImages() const {return bUseIntegralImages;}
protected:
virtual bool CloseImageData(unsigned int);
virtual bool WriteImageData(unsigned int);
virtual bool ReadImageData(unsigned int);
virtual bool CloseAllImageData();
static inline bool fileExists(const string& filename)
{
struct stat buf;
if (stat(filename.c_str(), &buf) != -1)
{
return true;
}
return false;
}
virtual void computeFeatures(const cv::Mat &, vector<cv::Mat> &imgFeatures) const;
virtual void computeFeaturesWithCorrCoeff(const cv::Mat &input, vector<cv::Mat> &imgFeatures) const;
virtual void computeHOGLike4SingleChannel(const cv::Mat &img, vector<cv::Mat> &vImg, int offset,
bool include_first_order_deriv, bool include_second_order_deriv) const;
virtual bool WriteImageIntOrFloat(const cv::Mat &, const char *) const;
virtual bool ReadImageIntOrFloat(cv::Mat &, const char *) const;
// vector<vector<cv::Mat> > imageData;
// vector<cv::Mat> gtImages;
};
class ImageDataSort
{
// Types
public:
class VideoStat
{
public:
string strVideoName;
vector<unsigned int> vectImagesIndices;
vector<unsigned int> vectNbSamplesPerLabel;
public:
VideoStat() {}
};
// Member variables
public:
ImageData *pImageData;
vector<VideoStat> vectVideoStats;
unsigned int iNbLabels;
public:
ImageDataSort(unsigned int);
bool SetData(ImageData *);
void GenerateRandomSequence(vector<unsigned int> &);
void RandomSplit_TrainValidationTest();
void GenerateRandomSequence_TrainingImagesIndices(vector<vector<unsigned int> > &);
};
}
#endif