If you haven't gathered all of your positive and negative samples please do so before continuing onto this page.
To verify that we all have everything ready to create samples and train a classifier we need to verify our structure of files:
D:
cv
opencv_workspace
info (dir)
data (dir)
opencv (dir)
pos (dir)
neg (dir)
trash (dir)
5050.png (file)
descriptors.py (file)
find_trash.py (file)
image_link_downloader.py (file)
Now let's go and copy some OpenCV files so we can start creating samples and vectors for the classifier. Navigate to opencv > build > x64 > vc14 > bin
Now copy everything in bin and paste it into the opencv_workspace directory which will reside with all scripts and other directories that we have in the workspace.
Now in command prompt you want to use the following command to create some positive samples:
opencv_createsamples -img 5050.png -bg neg.txt -info info\info.lst -pngoutput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5
This command allows us to create positive image samples based on the image we specify, bg is the background information which is basically the negative image samples. Info is where we will put info.lst output which is similar to neg.txt and then -pngoutput is where we will place the new generated samples.
Once the positives have finished being created it's time to create the vector file using the following command:
opencv_createsamples -info info\info.lst -w 20 -h 20 -vec positives.vec
Once this has finished (this shouldn't take long unless you have changed the width and height then this should be near instant. It's time to train the cascade using:
opencv_traincascade -data data -vec positives.vec -bg neg.txt -numPos 800 -numNeg 400 -numStages 10 -w 20 -h 20