Learning opencv-detailed explanation of hog features (feature points)

Source: Internet
Author: User

 

Hog (histogram of Oriented Gradient) is a feature descriptor used for target detection. This technique counts the number of partial direction gradients in an image, this method is similar to the edge direction histogram and scale-invariant feature transform. The difference is that hog's calculation improves accuracy based on consistent space density matrix. Navneet
Dalal and Bill triggs first proposed hog in cvpr in 05 years for pedestrian detection of static images or videos.


Hog feature principle:

The core idea of hog is that the shape of the detected local object can be described by the distribution of light intensity gradients or edge directions. By dividing the entire image into small connected areas (called cells), each cell generates a gradient histogram or the pixel edge direction in the cell, the combination of these histograms can represent the description child of the target to be detected. To improve accuracy, the local Histogram can calculate the light intensity of a large area (called block) in the image as a standardized measure, and then use this value (measure) normalize all cells in this block. this normalization process achieves better illumination/shadow immutability.

Compared with other descriptors, the descriptions obtained by hog maintain geometric and optical conversion immutability (unless the object direction changes ). Therefore, hog descriptors are especially suitable for human detection.

In layman's terms:

The hog feature extraction method is to convert an image:

1. grayscale (the image is regarded as an X, Y, Z (grayscale) three-dimensional image)

2. Divide the data into small cells (2*2)

3. Calculate the gradient (orientation) of each pixel in each cell)

4. Calculate the gradient histogram of each cell (number of different gradients) to form the descriptor of each cell.


Let's talk about the application and difference of hog, sift and PCA-SIFT:

Hog has no rotation and scale immutability, so the computation amount is small. In sift, each feature needs to be described using a 128-dimension vector, so the computation amount is relatively large.

So how to apply hog in pedestrian detection?

To solve the scale-invariant problem: Scaling images at different scales is equivalent to scaling templates at different scales.

To solve the problem of rotation-invariant: Create templates of different directions (generally 15*7) for matching.

In general, images of different scales are matched with Templates (15*7) in different directions, and each point is shown as an eight-direction gradient description.


Because of its large computational workload, sift does not need to be compared with pedestrian detection, and the PCA-SIFT method filters out many dimensions of information and only retains 20 main components, so it is only suitable for Object Detection with little behavior changes.


Method

Time

Scale

Rotation

Blur

Illumination

Affine

Sift

Common

Best

Best

Common

Common

Good

PCA-Sift

Good

Good

Good

Best

Good

Best

Surf

Best

Common

Common

Good

Best

Good




 

 

 

 

Hog is a gradient-based histogram extraction algorithm, which is very effective for human detection. It has been implemented in opencv2.2 +.

Encapsulated in the hogdescriptor class.

Hog is used to perform gradient statistics on the specified size area of an image. Can be called directly. Opencv makes it too complicated. When it is used, it will divide windows, blocks, and cells... A lot of things.

Here are three good articles.

Http://blog.csdn.net/raocong2010/archive/2011/03/11/6239431.aspx

This article explains window, block, and cell.

Http://gz-ricky.blogbus.com/logs/85326280.html

This article analyzes the number of results in the obtained vector result array.

Http://www.cnblogs.com/Anykong/archive/2011/04/06/anykong_opencv1.html

This article teaches you how to install opencv2.2 in vs2010. I used vc6 + opencv1.0 to write sift.

Note that the additional dependencies mentioned in this article only allow you to add a few basic items. If you want to use hog, opencv_objdetect220d.lib must be added.

You can see what the file name is...

Now that the background information is complete, let's give an example, that is, the main function is provided for demonstration.

Int _ tmain (INT argc, char ** argv) {mat trainimg; // The image trainimg to be analyzed = imread ("1.jpg", 1 ); // read the image hogdescriptor * hog = new hogdescriptor (cvsize (3, 3), cvsize (3, 3), cvsize (5, 10), cvsize (3, 3), 9 ); // For more information, see article 1, 2. Vector <float> descriptors; // result array hog-> compute (trainimg, descriptors, size (), size )); // call the calculation function to start printf ("% d \ n", descriptors. size (); // screen the size of the result array to see if it complies with the estimation in document 2. It is found that it is exactly the same. That article is very powerful. Sift ("1.jpg "); // This Is My change Write sift... for (INT I = 0; I <KP. size (); I ++) {// This cycle is used to calculate the gradient information of the Area 3*3 near the feature point in advance printf ("keypoint % d at % F \ n", I, kp [I]. first, Kp [I]. second); If (Kp [I]. first = picw) Kp [I]. first --; If (Kp [I]. first = 0) Kp [I]. first = 1; if (Kp [I]. second = Pich) Kp [I]. second --; If (Kp [I]. second = 0) Kp [I]. second = 1; int Pos = (Kp [I]. second-1) * (picw-2) + Kp [I]. first-1; for (Int J = 0; j <9; j ++) {res [J] + = descriptors [POS * 9 + J];} puts ("res Ult: "); For (INT I = 0; I <9; I ++) printf (" % lf ", Res [I]); // The result is output in text... Puts (""); iplimage * respic; // The result is output in a histogram. A res.jpg image is the background image of the histogram I have drawn. Without this image, the program cannot be run, comment out the following code: If (respic = cvloadimage ("res.jpg", 1) = 0) Return-1; double Maxx = 0; for (INT I = 0; I <9; I ++) if (Maxx <res [I]) Maxx = res [I]; for (INT I = 0; I <9; I ++) cvrectangle (respic, cvpoint (150 + 51 * I, (Maxx-res [I])/Maxx * (352-77) + 77 ), cvpoint (201 + 51 * I, 351), cv_rgb (0, 0, 0), 1, 8, 0); cvfont font; cvinitfont (& font, cv_font_hershey_simplex, 0.5, 0.5, 0); ITOA (INT) Maxx, outs, 10); cvputtext (respic, outs, cvpoint (), & font, cv_rgb (0, 0, 0); cvnamedwindow ("image1", 1); cvshowimage ("image1", respic); cvwaitkey (0); cvdestroywindow ("image1 ");}

Shift code: http://www.cvchina.info/codes/

 

Reference: http://blog.csdn.net/abcjennifer/article/details/7365651

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.