Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
4.64/5 (4 votes)
See more:
Hi All,

I need to create HarrCascade XML file to use it with OpenCV to tracking my object, and I have researched and I fond many way to create HaarCascade but it all of this is not clearly it all in C++ but I'm a C# developer and I work with OpenCV by Emgu however I'm not good in C++

I need function can create HaarCascade but I don't need C++ code


the function I need It take images and parse this images and make some calculation and create XML file having the result of this calculation

this function is one of OpenCV functions but I need it in C# (Emgu or OpenCVDotNet)


Regards,
Posted
Updated 29-Sep-11 8:00am
v4

Hi Ahmed,

I was going to try and give you are concise answer but I'm limited for time so I apologise. I've been using EMGU for several years now and I've looked into Haar Classifiers extensively. I intend to write an article at some point. There is a lot out there on Haar classifiers but a very good source is Here[^].

Now the tutorial isn't very clear but I did write c# program utilising EMGU to create the Haar classifier for you and I'll try and dig it out. Now the most important thing I need to make sure you understand is the complexity of forming a Haar cascade and make sure you wish to go down this line, it's not a quick process.

If your running Linux based OS then I can't help you much other than the steps you need. As for timing issues to generate a good Haar classifier you will need several thousand sample images and powerful processor (single core as multiple cores are not supported yet) and about a week or more access.

From the papers I have read it can take between a day to over a week to form these classifiers and yes there is no way of knowing if the classifier will work.

The Steps Involved



Sample Images


Positive
The website I provided a link to uses positive 5000 sample images I would recommend this to be the minimum you utilise while you may think you don't need as many all you will end up doing is wasting your time and producing a cascade that doesn't work. I would recommend producing a quick c# application using EMGU that allows you to select a ROI (region of interest) and save that to a file using a standard naming convention i.e. 1.jpg-5000.jpg

Negative
The number of Negative sample image does not have to be as high as positive ones but there needs to be a large amount generally tailored to the background the object your looking for will regularly occur on.

So if it's cars in a car park you need a few thousand images of the carpark without cars present and under different conditions snow, rain , night, day etc.

Creating Samples


This is done using a command line program now I would assume this is were you've found the C++ code but don't worry this is compiled for you if you examine the "Installation Directory of EMGU\Bin" folder you will find the follwing compiled files

opencv_createsamples.exe
opencv_haartraining.exe


Now if you jumped a head and tried to run one of these programs then you shouldn't have done all that will happen is the console window will open show some text and close usually before you will see the text.

To utilise these console applications they have to be called through command line from the start menu select RUN.. and type in CMD press enter and a console window will appear. Now type the location of opencv_createsamples.exe

e.g C:\EMGU\bin\opencv_createsamples.exe

It will simply display all the possible inputs for the command line call
VB
Usage: ./createsamples
  [-info <description_file_name>]
  [-img <image_file_name>]
  [-vec <vec_file_name>]
  [-bg <background_file_name>]
  [-num <number_of_samples = 1000>]
  [-bgcolor <background_color = 0>]
  [-inv] [-randinv] [-bgthresh <background_color_threshold = 80>]
  [-maxidev <max_intensity_deviation = 40>]
  [-maxxangle <max_x_rotation_angle = 1.100000>]
  [-maxyangle <max_y_rotation_angle = 1.100000>]
  [-maxzangle <max_z_rotation_angle = 0.500000>]
  [-show [<scale = 4.000000>]]
  [-w <sample_width = 24>]
  [-h <sample_height = 24>]



Now please look at the web page Here[^] and about a 1/3rd of the way down you will see 2. Create training samples from some follow th steps involved you will have tor create the -info <description_file_of_samples> file yourself it's just a simple text file holding relevant file information about your training sets.

The Cascade


I don't wish to re-write the webpage I've provided a link for so you will have to work through the steps it shows from now on. Despite it being a bit hard to read through once the samples are created you should utilise opencv_haartraining.exe from now on to generate your Haar Cascade. Calling it in the same command line fashion as before. If all goes well you will have a classifier that works.

Please take note that the more stages you have to your cascade the more accurate it will be however the longer it will take to complete calculations and generate the required XML file.

Notes



I hope this helps you and please feel free to ask extra questions I'll answer them as soon as I can when I have found the c# to generate the Haar classifiers I will write an article and upload it and of course post the link here

Cheers
Chris
 
Share this answer
 
Comments
Hassan Javed 22-Apr-13 10:17am    
C_johnson, i need your help, kinldy send me your contact adress at HassanRavian501@gmail.com, it will be a great favor.
First, don't ask for something ASAP. We are all volunteers here and don't have to answer you at all.

If you need help translating some of the C++ perhaps you could post a snippet and ask.
 
Share this answer
 
Comments
yousseffaraj 9-Jun-10 16:12pm    
Reason for my vote of 1
read before answering
Thanks for relay,

Yes it's a XML file but it's not just a string, I need function take images and give me a XML file, because I need use that XML file to detecting the same object in the image which we gave it to the function (HaarCascade creator)

Regards,
 
Share this answer
 
Comments
Member 9600065 29-Apr-13 23:54pm    
Hello guys... Am working on vehicle detection using Open CV. There is some program I found on you tube to learn the logic about this. Am using Visual Studio 2010 and OpenCv2.4.3 but unfortunately when ever I run the program I get these errors:
Warning 1 warning C4627: '#include <cv.h>': skipped when looking for precompiled header use c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 222 1 FirstProject
Warning 2 warning C4627: '#include <highgui.h>': skipped when looking for precompiled header use c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 223 1 FirstProject
Warning 3 warning C4627: '#include <opencv2 opencv.hpp="">': skipped when looking for precompiled header use c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 224 1 FirstProject
Error 4 error C2143: syntax error : missing ';' before '*' c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 230 1 FirstProject
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 230 1 FirstProject
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 230 1 FirstProject
Error 7 error C2065: 'CvCapture' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 242 1 FirstProject
Error 8 error C2065: 'capture' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 242 1 FirstProject
Error 9 error C2039: 'cout' : is not a member of 'std' c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 251 1 FirstProject
Error 10 error C2065: 'cout' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 251 1 FirstProject
Error 11 error C2039: 'cout' : is not a member of 'std' c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 258 1 FirstProject
Error 12 error C2065: 'cout' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 258 1 FirstProject
Error 13 error C2059: syntax error : ')' c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 261 1 FirstProject
Error 14 error C2065: 'capture' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 263 1 FirstProject
Error 15 error C3861: 'cvCaptureFromAVI': identifier not found c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 263 1 FirstProject
Error 16 error C2065: 'capture' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 265 1 FirstProject
Error 17 error C3861: 'cvNamedWindow': identifier not found c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 267 1 FirstProject
Error 18 error C2065: 'capture' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 269 1 FirstProject
Error 19 error C3861: 'cvQueryFrame': identifier not found c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 269 1 FirstProject
Error 20 error C2065: 'capture' : undeclared identifier c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.cpp 278 1 FirstProject
Error 21 error C3861: 'cvQueryFrame': identifier not found c:\users\user\documents\visual studio 2010\projects\firstproject\firstproject\firstproject.
I had to google to work out what you're talking about. If it's just an xml file, why do you need to create it programatically ? What makes it a HarrCascade file ? It's just xml ? Then creating it is quite trivial in C#, or C++, as XML is just a string.

You need to clarify what it is you're talking about.
 
Share this answer
 
Comments
yousseffaraj 9-Jun-10 16:28pm    
Reason for my vote of 1
you did not understand
Çağrı Daşkın 6-Nov-14 4:11am    
if you don't have any ideas about haar cascades, go and answer other questions. you don't have to try to answer everything.
I've already asked you to not post fake 'answers' and to edit your post. If it's XML, it IS just a text file, even if it contains the names of image files on your file system. So, the creation of an XML file is trivial, it's just a string. Figuring out how to get the data you need is the hard bit.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900