This article is mainly for the following URL blog content of the instance operation:
http://blog.csdn.net/byxdaz/article/details/4907211
In the above blog, the practice of OpenCV Training classifier is described in detail. Although his steps are very detailed, they cannot be quickly used in practice. So I summed up the content, can let people quickly hands-on, so for a novice, one hours can quickly master the method of classifier.
One: Prepare the positive and negative samples separately.
The normal sample is clipped to a uniform size and placed in a folder.
Put some photos unrelated to the image to be detected into a folder. -- Negative sample image size must not be less than the normal sample image size, and negative sample images can not have to detect the image information.
II: Basic DOS command line Introduction
Open the Run search box (thewindow7 system shortcut is ctrl+r, or you can find it under the Start Page) (windows8 The system is in the upper-right corner of the start page). In the Run Search box, enter "cmd" to find "command Prompt console";
Basic command-line method: If you want to enter a disk, enter "[ disk symbol ]:" +enter on the line.
For example: Enter f , enter f at the command line : then enter.
On disk if you want to enter a file, you should type: CD [filename] +enter .
For example: Enter the OPENCV folder on this disk: cd OPENCV and then enter.
If you want to clear the contents of the console, you can enter the CLS .
Such as:
Three: Negative sample production and positive sample preparation
generating negative sample files with DOS command
To open the command prompt console:
Use the command to enter the folder where your negative sample is located: For example, my f:\Opencv\minor
1: Input f: Press ENTER
2: Enter CD opencv\minornumber Press ENTER
Then enter the following command: dir/b >minor.dat
You will then have the minor.dat file in the appropriate folder for your negative sample image . Just open it with a Word document and delete the minor.dat line.
You can then generate a negative sample description file minor.dat .
The negative sample is ready to be taken. A negative sample description file is also generated in the same manner as described above. (This is for the positive sample preparation work).
The negative sample description file I made is Minor.dat,and the positive sample description file is nativesample.dat
I don't have a screenshot, this is the screenshot from the original blog. This step is relatively straightforward. Below is the most troublesome.
Four: Modify the positive text nativesample.dat file and change it to native.vec file.
Open nativesample.datwith Notepad or word documentand replace "BMP" with replace tool to " BMP 1 1 1 40 40 "
1 1 1 The number of pictures, the starting position and the width and height of the picture are represented.
To explain the meaning of the numbers above, there is a picture of that type, starting with the first one, to the end of the first one, wide, high
Then use the DOS command to convert the nativesample.dat file into a native.vec file.
Enter the home folder on the disk where the Nativesample.dat resides.
My disk and home folder is:F:\OPENCV
Input F: Press ENTER
Enter CD OPENCV carriage return
Use a DOS command (that is , the command line code that Windows runs inside) to convert.
there is a opencv_createsamples.exe program in a bin folder inside the OpenCV installation package.
The General bin file address is (opencv\build\x86\vc12\bin);
For example, my opencv_createsamples.exe program is under g:\OpenCV2.0\bin\.
Then enter the following command:
"G:\OpenCV2.0\bin\opencv_createsamples.exe"-info "Nativenumber\nativesamples.dat"-vec background\native.vec-num 8 -W 40-h 40
Explain:
Represents the opencv_createsamples.exe path:"G:\OpenCV2.0\bin\opencv_createsamples.exe"
Represents the nativesamples.dat file as a parameter passed to the above program:
-info "Nativenumber\nativesamples.dat"
On behalf of me to generate the VEC type of file, parameter I want to save the path and file name of this file
-vec Background\native.vec
The number of pictures representing me -num 8
Width and Height- w 40-h
V: Classifier training, generate txt file
Enter the command line:
"G:\OpenCV2.0\bin\opencv_haartraining.exe"-data Background-vec background\native.vec-bg Minornumber\minor.dat- NPOs 8-nneg 3-mem 200-mode all-w 40-h 40
-data background represents the address that I want to save the file as shown, because it is executed under f:\Opencv ,background is one of the subfolders, so do not write the full path.
-vec Background\native.vec refers to the file path of the parameter native.vec
-BG Minornumber\minor.dat refers to the parameter background file, which is the negative sample path
All the other COPY is good (the link to the blog is described in detail)
VI: Because the generated file is txt format, does not meet the final requirements of the classifier
So you need to convert the file in the final step, convert the txt file to an XML file (it's the only thing that can be a really loadable classifier file)
Put the plus and minus sample files (native.vec,minor.dat) under a folder,
Then enter the code as follows:
Front is the convert_cascade.exe file path.
--size refers to the width and height of the picture.
F:\\Opencv\\background is the address of the file
Finally, the full path of the address to be saved by the file
And then it's okay to enter. Such a classifier is ready, can be simple image detection.
OPECNCV Training Classifier Detailed arrangement