How to train my own waldboost detector to detect vehicles in OpenCV 3.3

asked 2017-10-23 21:45:26 -0500

teddyluo gravatar image

updated 2017-10-24 00:32:52 -0500

Recently I have paid many time in finding an efficient method to detect car objects using OpenCV. I have found that in opencv 3.0, one of the update (in the release note, ) says:

"Car detection using Waldboost, ACF by Vlad Shakhuro and Nikita Manovich "

And in Opencv 3.1, the update becomes:

"Improved ICF detector, waldboost implementation – opencv_contrib/xobjdetect (Vlad Shakhuro, Alexander Bovyrin)"

I have also found that some one had successfully applied the waldboost detector to detect cars, such as the following two papers:

  1. C. Caraffi, T. Vojíř, J. Trefný, J. Šochman and J. Matas, "A system for real-time detection and tracking of vehicles from a single car-mounted camera," 2012 15th International IEEE Conference on Intelligent Transportation Systems, Anchorage, AK, 2012, pp. 975-982.
  2. J. Sochman and J. Matas, "WaldBoost - learning for time constrained sequential detection," 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR'05), 2005, pp. 150-156 vol. 2.

These achievements indicate that Waldboost detector should be valid / suitable for car detection, which is well fit my purpose.

To accomplish this goal, I have collect enough positive samples/negative samples. I use opencv 3.3 with opencv 3.3 contribution modules for experiment. After correct configuration, there should be an executable file named "opencv_waldboost_detector", which can be used for training my own classifier.

I used the following command to train my classifier (samples in folder "positiveImgs" are scaled to 24x24 according to the code, if I fully understand)(however, I do not apply any scale operations to the images in "negativeImgs", only keeping them unchanged):

./opencv_waldboost_detector train waldboost.xml ./positiveImgs ./negativeImgs

After finishing my training, the output of the terminal ( I work under ubuntu 16.04) is somewhat like (only an example, because I have lost the original data while writing this question):

i=1009 feat= 6439 thr=195 casthr=0.586 alpha=0.095 err=0.453 loss=1.044e-2 neg 361/353 i=1010 feat= 6423 thr=240 casthr=0.684 alpha=0.098 err=0.451 loss=1.089e-2 neg 353/345 i=1011 feat= 1312 thr= 97 casthr=0.578 alpha=0.106 err=0.447 loss=1.050e-2 neg 345/345

And also I got a *.xml file which is the target classifier. However, when I test this classifier, the detect objects are very strange. It can not detect any valid car, but only some background rectangle. I want to know what is wrong with this trained classier. Or are there any important steps which I ignored? (I do not know how to upload the screenshots)

End state of training from terminal: image description

training examples (negative images, around 50000 examples ): image description

training examples (positive images, about 10000+ examples): image description

detect results (using the trained xml file ): image description

Could someone tells me what is wrong with the waldboost detector? why it does not work for my problem?

Thank you for anyone who answers this question in advance.

edit retag flag offensive close merge delete


somehow, your output does not show. can you try again ?

berak gravatar imageberak ( 2017-10-23 23:53:41 -0500 )edit

thank you very much. I have edited it.

teddyluo gravatar imageteddyluo ( 2017-10-24 00:33:46 -0500 )edit

i'd say, you did everything correct, and it's the code, which is broken / to blame.

other folks here have reported the same problem before.

(it's also no more using icf/acf features, like mentioned in the paper, but an adapted version of lbp features)

(you seem to have a really nice dataset there !)

berak gravatar imageberak ( 2017-10-24 00:43:11 -0500 )edit

Many thanks. So, can you help me to identify that why my trained .xml file can not detect any cars?

teddyluo gravatar imageteddyluo ( 2017-10-24 00:51:56 -0500 )edit

sorry, but i cannot help with your trained detector. (how even ?)

apart from the images, there is nothing to configure here (no params or magic numbers), and again, your data looks good to me.

it's sad, but most probably you'll have to look for an alternative way, like HOGDescriptor or neural networks like yolo or ssd.

berak gravatar imageberak ( 2017-10-24 00:58:55 -0500 )edit

I wonder that If the waldboost detect cannot work well, why opencv 3.x still collect it into the opencv_contrib modules. Have they considered removing it from opencv_contrib in the future?

teddyluo gravatar imageteddyluo ( 2017-10-24 01:13:27 -0500 )edit

idk. maybe there's hope to fix it. (it'll just need a lot of effort)

berak gravatar imageberak ( 2017-10-24 01:18:31 -0500 )edit