5 const int cell_size,
const int block_per_cell,
6 const int n_bins,
const float angle) :
15 const float &angle,
int &lower_index,
int &higher_index) {
16 float nearest_lower = FLT_MAX;
17 float nearest_higher = FLT_MAX;
23 if (distance < nearest_lower) {
24 nearest_lower = distance;
28 if (distance < nearest_higher) {
29 nearest_higher = distance;
37 const cv::Mat &image, cv::Mat &hog_bins) {
40 cv::Sobel(image, xsobel, CV_32F, 1, 0, 7);
41 cv::Sobel(image, ysobel, CV_32F, 0, 1, 7);
44 cv::cartToPolar(xsobel, ysobel, Imag, Iang,
true);
45 cv::add(Iang, cv::Scalar(
ANGLE), Iang, Iang < 0);
46 cv::add(Iang, cv::Scalar(-
ANGLE), Iang, Iang >=
ANGLE);
47 cv::Mat orientation_histogram;
48 for (
int j = 0; j < image.rows; j +=
CELL) {
49 for (
int i = 0; i < image.cols; i +=
CELL) {
50 cv::Rect rect = cv::Rect(i, j,
CELL,
CELL);
51 if ((rect.x + rect.width <= image.cols) &&
52 (rect.y + rect.height <= image.rows)) {
53 cv::Mat bin = cv::Mat::zeros(1,
N_BINS, CV_32F);
54 for (
int y = rect.y;
y < (rect.y + rect.height);
y++) {
55 for (
int x = rect.x;
x < (rect.x + rect.width);
x++) {
56 float angle =
static_cast<float>(Iang.at<
float>(
y,
x));
60 float l_ratio = 1 - (angle - l_bin)/
BINS_ANGLE;
61 float h_ratio = 1 + (angle - h_bin)/
BINS_ANGLE;
64 bin.at<
float>(0, l_index) +=
65 (Imag.at<
float>(y,
x) * l_ratio);
66 bin.at<
float>(0, h_index) +=
67 (Imag.at<
float>(y,
x) * h_ratio);
70 orientation_histogram.push_back(bin);
74 hog_bins = orientation_histogram.clone();
78 const int col,
const int row, cv::Mat &bins) {
81 for (
int j = row; j < (row +
BLOCK); j++) {
82 for (
int i = col; i < (col +
BLOCK); i++) {
84 for (
int k = 0; k <
N_BINS; k++) {
85 block_hogMD.at<
float>(0, icounter++) = bins.at<
float>(index);
93 const cv::Mat &image, cv::Mat &bins, cv::Mat &featureMD) {
94 for (
int j = 0; j < image.rows; j +=
CELL) {
95 for (
int i = 0; i < image.cols; i +=
CELL) {
97 if ((rect.x + rect.width <= image.cols) &&
98 (rect.y + rect.height <= image.rows)) {
101 featureMD.push_back(hogMD);
108 const cv::Mat &
img) {
109 cv::Mat image = img.clone();
110 if (image.type() != CV_8U) {
111 cv::cvtColor(image, image, CV_BGR2GRAY);
116 getHOG(image, bins, featureMD);
117 featureMD = featureMD.reshape(1, 1);
123 const cv::Mat &patch, std::vector<cv::Mat> &imageHOG,
124 const int distance_type) {
126 T argMinDistance = FLT_MAX;
127 for (
int i = 0; i < imageHOG.size(); i++) {
128 cv::Mat img_hog = imageHOG[i];
129 T d = compareHist(patch, img_hog, distance_type);
130 if (d < argMinDistance) {
131 argMinDistance =
static_cast<double>(
d);
134 sum =
static_cast<T>(argMinDistance);
135 return static_cast<T>(sum);
virtual void bilinearBinVoting(const float &, int &, int &)
virtual cv::Mat blockGradient(const int, const int, cv::Mat &)
virtual void getHOG(const cv::Mat &, cv::Mat &, cv::Mat &)
T computeHOGHistogramDistances(const cv::Mat &, std::vector< cv::Mat > &, const int=CV_COMP_BHATTACHARYYA)
virtual void imageGradient(const cv::Mat &, cv::Mat &)
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
virtual cv::Mat computeHOG(const cv::Mat &)
pointer BLOCK(context *, pointer)
TFSIMD_FORCE_INLINE Vector3 & normalize()
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
HOGFeatureDescriptor(const int=8, const int=2, const int=9, const float=180.0f)