OPENCV Extraction Hog

Source: Internet
Author: User

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

Encapsulated in the Hogdescriptor class.

Hog is actually a picture of a designated size area for gradient statistics. can be called directly. OpenCV it too complicated, use the time to divide what Window,block,cell what ... A whole bunch of stuff.

Here are three very good articles to introduce.

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

This article is an explanation of Window,block,cell.

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

This article is an analysis of the number of results in an array of vector results obtained.

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

This article is a very good article to teach you how to install opencv2.2 under VS2010. I used to write sift when I was vc6+opencv1.0.

one place to note, however, is that the additional dependencies in this article only allow you to add a few basic ones. If you want to use hog, you must add Opencv_objdetect220d.lib

look at the name of the file to know what it is ...

Well, the background information is finished, give an example, is my main function to let out to do a demonstration.

int _tmain (int argc, char** argv)
{
Mat trainimg; Pictures that need to be analyzed
Trainimg=imread ("1.jpg", 1); Reading pictures
Hogdescriptor *hog=new Hogdescriptor (cvsize (3,3), Cvsize (3,3), Cvsize (5,10), Cvsize (3,3), 9); See reference article 1,2
vector<float>descriptors;//result Array
Hog->compute (Trainimg, Descriptors,size (1,1), Size (0,0)); Call the calculation function to start the calculation
printf ("%d\n", Descriptors.size ()); Screen the size of the result array to see if it conforms to the estimate of the 2, and find exactly the same, that article is very force

Sift ("1.jpg"); This is my rewriting of the sift ...
for (int i=0;i<kp.size (); i++) {//This loop is the gradient information statistic I use to advance the 3*3 area near the feature point.
printf ("KeyPoint%d at%f%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 ("Result:");
for (int i=0;i<9;i++) printf ("%lf", Res[i]); Results in text output ...
Puts ("");
Iplimage * RESPIC; Results with the histogram output, there is a res.jpg is my picture of the histogram background, no this diagram can not run the program, the code from the following comments off
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 (53,83), &font,cv_rgb (0, 0, 0));
Cvnamedwindow ("Image1", 1);
Cvshowimage ("Image1", respic);
Cvwaitkey (0);
Cvdestroywindow ("Image1");

}

That night I also spent a long time on the opencv1.1 sift to the SIFT based on opencv2.2, there are hundreds of mistakes, changed me one hours ... Tnnd

Change the for (i=1;i<=1;i++) this to for (int i=1;i<=1;i++) This is a C + + specification issue

And then for what system function call not clear error, add a bit of forced conversion

For the Max function ... I don't know where he's calling.

It's not hard to string up these two programs, and there's nothing to write about. The main thing is that Hog's call on the Internet has no information. In fact, Hog is a statistical program based on interval, several interval this parameter is nbins.

Hog is mainly used for human body recognition. If it's opencv2.2, it can be found in its sample.

C:\OpenCV2.2\samples\cpp\peopledetect.cpp

There's a opencv2.3 now, but I didn't find a version that fits VS2010, which looks like a Linux version ... So I used 2.2.

The person who gave me the project is quite satisfied, give the money quite quickly ... I still don't think he's going to supply me with the tail.

In fact, the difficulty of the project is sift ... Mainly for the big horse write, already have a lot of understanding of sift, can in a night to write his program (give me project that person the next day if can't get out of the program can not graduate ... Tragedy) If you want to sift code, leave a message (I do not have a message in this space), in fact, sift code in many places have.

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.