# HOG feature I learned about HOG feature from here following this tutorial I am trying to create HOG feature...I have approached till here..

#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace ml;
using namespace std;

void main()
{
Mat h1,h2,h3;
image.convertTo(image,CV_32F,1/255.0);
imshow("out",image);
Mat dx,dy; //image axial derivatives..
Sobel(image,dx,CV_32F,1,0,1);
Sobel(image,dy,CV_32F,0,1,1);
imshow("dx",dx);
imshow("dy",dy);
Mat mag,angle;
cartToPolar(dx,dy,mag,angle);
imshow("magnitude",mag);
imshow("angle",angle);

waitKey(0);
_getch();

}


I have obtained image~derivative of orignal image and mapped to polar coordinate system.Now I obtained two matrices represent gradient and its orientation namely mag and angle respectively.Now I have to obtain histogram of gradients over 8x8 patch of image...how shall I proceed next

I AM NOT FOND OF USING PRE BUILD HOG DESCRIPTOR..

I am quite sure its not a good idea...But

Thank you

edit retag close merge delete

Sort by » oldest newest most voted

that shouldn't be dificult. first, you want the angle in degrees, not radians:

cartToPolar(dx,dy,mag,angle, true);


then, it's a double for loop, to get 8x8 patches:

for (int r=0; r<img.rows; r += 8) {
for (int c=0; c<img.cols; c+=8) {
Mat_<float> patch_angle = angle(Rect(c,r,8,8));
Mat_<float> patch_mag = mag(Rect(c,r,8,8));
}
}


then, for each patch, you need to make a histogram, an array of counters:

Mat_<float> hist = Mat_<float>::zeros(1,9);


now, iterate over the values in patch_angle and patch_mag, and increase the resp. bin:

int bin = (int(patch_angle(r,c) % 180) / 20; //results in a value [0..8]
hist(0, bin) += patch_mag(r,c);

more

So for each patch I made histogram of oriented gradients...I did the same as you suggested.Now how can I use is as feature over which I further apply dimension reduction(PCA) algorithms and feed to Neural Network to train them

here's a PCA example . (basically: you construct a PCA from your data, then project the data with the (reduced set of) eigenvectors, a matrix multiplication, like transformations in 3d)

if you use the search bar on this site, you'll find many examples for training ann's

actually I don't understand basic of PCA,so I need help for good website for good tutorial....:(

you were the 3d guy, no ? think of it as a coordinate transformation. 1st find the base coord system, then use it to transform the data to a space with less dimensions

what's difference bw Mat_<float> and Mat

it's a templated type, and you don't need the .at<float> when accessing elements later

Why we take only 9 buckets for representing 128(8x8x2) pixle values ...we can take more...

Official site

GitHub

Wiki

Documentation