yesterday saw a day of OPENCV training classifier information, want to try. After yesterday's toss of the day finally successful training out of their own classifier, although the effect is not good, but is a better beginning. I encountered a lot of problems throughout the process, here and share with you, hope to help you.
1. The process of creating a positive sample basically follows these steps:
1) Make a positive sample description file that describes the positive sample file name (including absolute path or relative path), the number of positive samples, and the position and size of each positive sample in the picture. A typical positive sample description file is as follows:
Face_100/face00001.bmp 1 0 0 20 20
Face_100/face00002.bmp 1 0 0 20 20
Face_100/face00003.bmp 1 0 0 20 20
A sample description file can be generated using the DOS command combined with the EditPlus software. by typing dir face_100/b > Samples.dat in the appropriate directory under DOS, a samples.dat is generated that contains all the list of positive sample file names, but no relative pathname and positive sample location information. The way to add "face _100/" at the beginning of each line of the Samples.dat file is to use EditPlus, select all the rows first, then press the TAB key to add a tab stop for each line, and then replace all the tab stops with "Face _100/". You can add "20 1 0 0 20" to each line by replacing "BMP" with "BMP 1 0 0 20 20".
2) Run the Createsamples program. If running directly in the VC environment, you can set the run parameters in the program arguments bar of the Project\settings\debug property page. The following is an example of a run parameter:
-info F:\FaceDetect\samples.dat-vec F:\FaceDetect\samples.vec-num 200-w 20-h 20
It indicates that there are 200 samples, the sample width is 20, the height is 20, the positive sample description file is Samples.dat, and the result is output to Samples.vec.
3) A *.vec file will be generated when the run is finished. The file contains the number of positive samples, width and height, and all sample image data
Need to note: 1, the face of the sample library how to get, I choose is orl face Sample library, this may use more, but this sample library face size is 92*112, preferably pre-cut into 20*20, can be used PS batch processing operation completed, specific steps to find Baidu.
2, the face sample size is best 20*20~25*25, not too big, otherwise the calculation is too large, easy memory is not enough
3, the sample as much as possible
4, edit the description file when the software selection, I chose dos+notepad++, EditPlus did not find the pure version, under a virus, let me depressed.
2, the creation process of negative samples
The process is basically the same as the positive sample, but
1, negative samples do not need to create. vec files like positive samples, only the. dat files are required.
2, negative samples of the description file without a negative sample of the detailed description information (such as: 1 0 0 20 20) only need to relative path or absolute path and picture file name, this is to remember, I eat a big loss.
3, the figure sample picture can not be too big, this also must remember, and although the OPENCV can automatically cut the negative sample file size to be consistent with the positive sample size, but we'd better cut ourselves in advance, this can reduce out-of-memory errors, and increase training speed.
3. Training process
training Process I encountered the most difficulties, the longest time, mainly positive samples and negative sample creation of the non-standard, the training process error is mainly encountered three kinds of, 1) no identification; 2) Invalid background description file (e.g. sample description file); 3) Insufficient memory.
1, do not identify the cause of the error (not too clear), the individual is not found the corresponding picture file, the solution is to check your DOS environment, run Opencv_haartraining.exe, where your path, such as your path is e:\shiyan-> Then your positive and negative sample profiles are relative paths, and vice versa. 2) The parameters-npos and-nneg values must be consistent with the description file. 3) Check the command carefully for a wrong call .
2. Invalid background description file Resolution 1) OPENCV_ The Haartraining.exe parameter-W and-H values need to be consistent with negative samples (it is strongly recommended that positive and negative samples be cropped in advance to a consistent size to avoid errors here); 2) The previous reference to the negative sample description file does not require the details of the sample (this is the last problem I found, look at the data to be careful)
3, Insufficient memory solution: 1) positive sample and negative sample size should not be too large, generally for 20*20, not more than 25*25;2) negative sample number should not be too much, negative sample quantity too much, increase the calculation amount
This is the problem I encountered in training my own classifier and solutions, I hope it will be useful to you. In fact, there are still some problems not clear, to follow up, but also hope that you have a good solution, timely reply, we progress together.
1. The number of negative samples? See a lot of data negative sample number is generally greater than equal to the number of positive samples, can be less than it? Pending validation
2. How is the progression of the classifier determined, and what is the principle?
If you know the answer, please reply, thank you.
Welcome to reprint, but please indicate the source, thank you!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
OPENCV Training Classifier is a number of errors and solutions