2 - c++ wrapper for the piotr toolbox
3 Created by Tomas Vojir, 2014
7 #ifndef FHOG_HEADER_7813784354687
8 #define FHOG_HEADER_7813784354687
11 #include <opencv2/opencv.hpp>
13 #include "gradientMex.h"
14 #include "scale_vars.hpp"
21 //description: extract hist. of gradients(use_hog == 0), hog(use_hog == 1) or fhog(use_hog == 2)
22 //input: float one channel image as input, hog type
23 //return: computed descriptor
24 static void extract(const cv::Mat & img, Scale_vars & vars,int use_hog = 2, int bin_size = 4, int n_orients = 9, int soft_bin = -1, float clip = 0.2)
26 // d image dimension -> gray image d = 1
27 // h, w -> height, width of image
29 // I -> input image, M, O -> mag, orientation OUTPUT
30 int h = img.rows, w = img.cols, d = 1;
33 std::cerr << "I must be at least 2x2." << std::endl;
37 // //image rows-by-rows
38 // float * I = new float[h*w];
39 // for (int y = 0; y < h; ++y) {
40 // const float * row_ptr = img.ptr<float>(y);
41 // for (int x = 0; x < w; ++x) {
42 // I[y*w + x] = row_ptr[x];
47 float * I = new float[h*w];
48 for (int x = 0; x < w; ++x) {
49 for (int y = 0; y < h; ++y) {
50 I[x*h + y] = img.at<float>(y, x)/255.f;
54 float *M = new float[h*w], *O = new float[h*w];
55 gradMag(I, M, O, h, w, d, full);
57 int n_chns = (use_hog == 0) ? n_orients : (use_hog==1 ? n_orients*4 : n_orients*3+5);
58 int hb = h/bin_size, wb = w/bin_size;
60 float *H = new float[hb*wb*n_chns];
61 memset(H, 0, hb*wb*n_chns*sizeof(float));
64 full = false; //by default
65 gradHist( M, O, H, h, w, bin_size, n_orients, soft_bin, full );
66 } else if (use_hog == 1) {
67 full = false; //by default
68 hog( M, O, H, h, w, bin_size, n_orients, soft_bin, full, clip );
70 fhog( M, O, H, h, w, bin_size, n_orients, soft_bin, clip );
73 //convert, assuming row-by-row-by-channel storage
74 int n_res_channels = (use_hog == 2) ? n_chns-1 : n_chns; //last channel all zeros for fhog
75 vars.patch_feats.clear();
76 for (int i = 0; i < n_res_channels; ++i) {
78 // cv::Mat desc(hb, wb, CV_32F, (H+hb*wb*i));
81 cv::Mat desc(hb, wb, CV_32F);
82 for (int x = 0; x < wb; ++x) {
83 for (int y = 0; y < hb; ++y) {
84 desc.at<float>(y,x) = H[i*hb*wb + x*hb + y];
88 vars.patch_feats.push_back(desc.clone());
102 #endif //FHOG_HEADER_7813784354687