Ask Your Question

How to train cascade classifier

asked 2012-07-03 13:13:18 -0600

KDS gravatar image

updated 2012-08-09 01:48:58 -0600

Kirill Kornyakov gravatar image


I am having trouble implementing the HaarDetectObjects function (using OpenCV / Python). The script attempts to identify electronic components (resistors, capacitors, etc.) on a PCB. I have created a large bank of positive and negative images to use for the Haar Training, but am unsure how to go about taking the list of images and generating the cascade XML file. Following some information found online, I have created two text files listing the positive and negative images. My understanding is that these files will then be used by the program located at opencv\samples\c\convert_cascade, which will need to be compiled. However, I have been unable to compile the necessary files to be able to run convert_cascade.

If anyone has generated a custom cascade and knows what I might be doing wrong, please let me know. I greatly appreciate your help and thank you in advance for your time. If any more information would be helpful, please let me know.

In summary, I am at a loss for how to generate a cascade XML file.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-07-04 08:41:00 -0600

rantanplan gravatar image

updated 2012-10-02 05:58:26 -0600

V.G. gravatar image

you have to create a .vec file from your positives file using the opencv_createsamples tool, e.g.

opencv_createsamples -info positives.dat -num 1000 -vec positives.vec -w 24 -h 24

This would create a positives.vec file from 1000 positve samples listed in positives.dat. The sample width and height are 24. This .vec file is than passed to opencv_traincascade for training. For the negatives you just pass a file containing the file names of your negative samples. For further informations i found this, that, and that good resources. But you've probably found them already...

To create the opencv_createsamples tool you should configure OpenCV with BUILD_EXAMPLES=ON (i think).

edit flag offensive delete link more


Thank you, very much. I greatly appreciate your help. I just realized that I had not thanked you for your answer - sorry for the delay. Regards, KDS

KDS gravatar imageKDS ( 2012-08-07 10:39:35 -0600 )edit

KDS, the good way to thank for an answer is by marking it as the correct answer :). Only you as owner of the question can do that.

Michael Burdinov gravatar imageMichael Burdinov ( 2012-08-09 02:00:25 -0600 )edit

Can someone describe what the "mergevec" function actually does? it seems that for every positive sample, it generates a *.vec file. But then we still need to merge them? I'm at a loss on this merging process. Thanks

Trak888 gravatar imageTrak888 ( 2014-02-20 22:21:53 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2012-07-03 13:13:18 -0600

Seen: 2,670 times

Last updated: Oct 02 '12