Ask Your Question

Extending Haar features

asked 2013-08-07 20:08:19 -0600

Kholofelo gravatar image

updated 2013-08-07 20:43:06 -0600

Short question

How can I use custom features in a Haar cascade classifier? Custom feature implies that using features that are not supported by opencv. i.e not one of these:

image description

More details:

I need to implement and train my own custom Haar-cascade classifier in opencv.

There is already an option to train the classifier with my own dataset but I also need to change the basic Haar-features used. All I can do is choose from the given subsets (Edge features,Line features and Center-surround features). I already have a set of Haar-features I need to use which I tested on Matlab.

I am looking of some way to specify my features (for example provide a couple of rects which define my Haar-features).

For example suppose I needed to create this feature:

Custom Haar-feature

It would be helpful if I could specify this feature to be part of the classifier's feature space. Supposing that the square is 20x20. I would like to specify it as follows:

  • rect1 (0, 0, 9 9)
  • rect2 (10, 0,19, 9)
  • rect3 (0, 10,9,19)
  • rect4 (10,10,19,19)

Assuming that the rects are defined by their two corners in the form (xi,yi,xf,yf).

Thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-08-08 01:42:36 -0600

Basically this will lead you to the following steps:

  1. Break down the original source code of the cascade classification process.
  2. Go through the code step by step until the original wavelets are read in. Since the trainings needs you to specify feature type, I guess they have it somewhere hard coded inside.
  3. Add lines of code with your new features.
  4. Rebuild the whole cascade classification training.

I guess it is doable but it won't be straightforward. Once you have found where it is done, what you could do is create a pull request with an interface for adding the feature sets. This could lead to the function being implemented in the original openCV library.

edit flag offensive delete link more


Thanks Steven.

I have noticed that the actual xml file used in the cascade classifier has some defines the rectangles used for the features as well as the threshold for classification. So the classifier has to be trained accordingly and I think the generated xml file would also have the definitions of the features (their respective rectangles and threshold). (So the looking at the classification process alone won't be sufficient).

So I will try your suggested approach but I'll try and find the source used for training and producing the xml file. I will keep you updated. Thanks again.

Kholofelo gravatar imageKholofelo ( 2013-08-08 08:03:31 -0600 )edit

Yeah first step will be to look at the training of a cascade classifier. Somewhere it has to be possible to add more structures. Just will take you some time.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-08 08:07:59 -0600 )edit

So I have narrowed my search down to the class CvHaarEvaluator::Feature::Feature in the file haarfeatures.cpp which is the folder PATH_TO_OPENCVLIB/apps/traincascade. Once I actually get this to work I will update the question with an answer.

Kholofelo gravatar imageKholofelo ( 2013-08-12 08:22:33 -0600 )edit

Good one! And if it works out, do a feature suggestion with your adaptation at the development forum. I guess this is an interesting one to add to the functionality.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-12 08:34:32 -0600 )edit

Hey Steven, thanks a lot for your answer. I ended up needing to make many more changes and it was much better to write my own classifier from scratch.

Kholofelo gravatar imageKholofelo ( 2013-10-08 07:52:19 -0600 )edit

Care to share the results through a github repository or so?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-08 12:03:19 -0600 )edit

Question Tools



Asked: 2013-08-07 20:08:19 -0600

Seen: 798 times

Last updated: Aug 08 '13