-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhog.h
More file actions
117 lines (103 loc) · 3.26 KB
/
hog.h
File metadata and controls
117 lines (103 loc) · 3.26 KB
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
#ifndef HOG_H
#define HOG_H
#include "constant.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cassert>
class Hog {
public:
// constant
const unsigned kCellSize;
const unsigned kBlockSize;
const unsigned kImageWidth;
const unsigned kImageHeight;
const unsigned kOrientation;
const unsigned kTotalDimension;
const double kAngle;
const unsigned kHistgram;
private:
// reference of destination of feature
std::vector<double> destination_;
// image matrix
cv::Mat source_;
// feature of histogram_
std::vector<double> histogram_;
void make_histgram();
void make_feature();
public:
// constructor & process
explicit Hog(const char* name,
unsigned cell_size, unsigned block_size, unsigned image_width,
unsigned image_height, unsigned orientation, unsigned type = 0)
: kCellSize(cell_size),
kBlockSize(block_size),
kImageWidth(image_width),
kImageHeight(image_height),
kOrientation(orientation),
kTotalDimension((kImageWidth / kCellSize - kBlockSize + 1) *
(kImageHeight / kCellSize - kBlockSize + 1) *
(kBlockSize * kBlockSize * kOrientation)),
kAngle(180.0 / (double)kOrientation),
kHistgram((kImageWidth / kCellSize) * (kImageHeight / kCellSize)
* kOrientation),
destination_(kTotalDimension),
source_(cv::imread(name, 0)),
histogram_(kHistgram, 0) {
// resize image
cv::resize(source_, source_, cv::Size(kImageWidth, kImageHeight));
// affine convert
switch (type) {
case 1: {
cv::Point2f center(source_.rows * 0.5, source_.cols * 0.5);
// rotate
cv::warpAffine(source_, source_,
cv::getRotationMatrix2D(center, 10, 1.0f), source_.size());
break;
}
case 2: {
// nop
assert(false);
}
}
make_histgram();
make_feature();
}
// cv::Mat が引数ありコンストラクタ
explicit Hog(const cv::Mat& mat,
unsigned cell_size, unsigned block_size, unsigned image_width,
unsigned image_height, unsigned orientation)
: kCellSize(cell_size),
kBlockSize(block_size),
kImageWidth(image_width),
kImageHeight(image_height),
kOrientation(orientation),
kTotalDimension((kImageWidth / kCellSize - kBlockSize + 1) *
(kImageHeight / kCellSize - kBlockSize + 1) *
(kBlockSize * kBlockSize * kOrientation)),
kAngle(180.0 / (double)kOrientation),
kHistgram((kImageWidth / kCellSize) * (kImageHeight / kCellSize)
* kOrientation),
destination_(kTotalDimension),
source_(mat),
histogram_(kHistgram, 0) {
// 画像サイズが異なる場合は処理停止
if (source_.rows != kResizeX || source_.cols != kResizeY)
assert(false);
make_histgram();
make_feature();
}
~Hog() {
source_.release();
}
double operator[](unsigned idx) const {
return destination_.at(idx);
}
const std::vector<double> & get_data() const {
return destination_;
}
};
#endif // HOG_H