1

I want to create my own haarcascade for license plates. I have found a GUI called Cascade-Trainer-GUI that does this. I'm using Windows 10. You can download gui from here:

http://amin-ahmadi.com/cascade-trainer-gui/

I have two folders with positive and negative images. There are about 650 positive images and 570 negative images.

When I run the program, it finishes in a couple of seconds, but I do not get cascade.xml file. I get .txt file, and in the end of that txt file it says :

OpenCV Error: Insufficient memory (Failed to allocate 1357715212 bytes) in cv::OutOfMemoryError, file D:\cv\opencv_3.2.0\sources_withTextModule\modules\core\src\alloc.cpp, line 52

I have followed the documentation and I have watched some videos on youtube, but I do not know what am I doing wrong.

These are performance of my PC when I try to train my cascade:

enter image description here

I have tried to clean my disk space and to shut down all other programs so that I can increase my RAM memory but I still get the same error.

I have tried to reduce buffer size from 1024 to 256. In that case it starts working but after 5-6 samples (10 minutes )it shows an error Insufficient Count of Samples, I have tried to reduce parameter number of max features from 100% to 70%, but I get the same error after same time.

You can download the images from here, I have sorted them into positive and negative:

https://www.sendspace.com/file/uo18pu

Do you know what am I doing wrong, what should I do to fix this? What parameters should I choose in this gui?

Also, is there some kind of app that creates haar cascades online?

taga
  • 3,537
  • 13
  • 53
  • 119

1 Answers1

0

I believe that you problem is due to the size of the image patches used for training. In the original Violaj-Jones paper they used patches of 20x20 pixels, which resulted in more than 180,000 features. To find the best set of features in each stage of the cascade, the boosting algorithm must find the best feature/threshold combination (the weak classifier is a perceptron) in each iteration. This involves to calcule the entropy for N features with M possible thresholds, where M coincides whit the number of training images. Then it is required MxN memory spaces in each boosting iteration. Assuming that internally this program uses floating precision, then you need MxNx4 bytes of memory approximately for each boosting iteration. In you case, for 20x20 image patches this is only 180000x(119+114)x4=167,760,000 bytes, that is, approximately 0.16 GB, but this number may be much larger if the size of the training patches is larger or if the set of base features that you use is larger than the original Violaj-Jones paper (in this paper the set of base features is 4, but there is another set called haar-like) . Then, I believe that you need to configure the size of the image patches of training.

  • Because Im working with images of licence plates, i set 'Sample width to 85' and 'sample height to 28' (rectangle), negative images are mostly squared but their height varies from 100 to 1000. Can toy tell me what should I do to make this work, how to to configure the size of the image patches of training? – taga Nov 08 '19 at 13:22
  • Should convert all negative images to be same size, for example 100x100 or 200x200? – taga Nov 08 '19 at 13:25
  • What I would recommend is to use another type of algorithm to detect plates, such as hought-transform. In any case, if you decide to try with the haar cascade, select LBP features and use training patches no larger than 24x24 pixeles, otherwise you will need a lot of RAM. – Roger Figueroa Quintero Nov 08 '19 at 13:28
  • I have 8gb ram, is that enough? Also, If I use LBP features, Is the coding process in Python and OpenCV the same as with haar cascades? – taga Nov 08 '19 at 13:36
  • The set of features N grows with the size of the patches that you use for the training. If you want to make an approximate calculation for an HxW size window follow the following link (https://stackoverflow.com/questions/40198217/number-of-haar-like-features-in-24x24-window) where they perform the calculation numerically (using a simple code that you can implement in python or C++). Then, you calculate NXMX4 and this gives you the amount of RAM required. – Roger Figueroa Quintero Nov 08 '19 at 13:46
  • On the other hand, I recommend LBP because I have read many papers that report better results using LBP (for example https://www.hindawi.com/journals/mse/2015/948960/). – Roger Figueroa Quintero Nov 08 '19 at 13:46