How to train an image classifier
Based on the OpenCV Book. p.513 Learning New Objects
1. Positive Images
The input. Camera input produces consistent images. Overfit?
Getting the rectangles
* http://stackoverflow.com/questions/36296763/drawing-as-input-for-hit-on-amazon-mechnical-turk
* https://vision.princeton.edu/pvt/DrawMe/
Do we need to have the rectangles all with same size?
The bottle should be only vertical?
shot a video wtih cheese, copied webm to working directory
Using ffmpeg to convert video to frames https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
Convert video to frames
mkdir video
ffmpeg -i yourvideo.webm -vf fps=5 video/frame%04d.jpg
Or take pictures with the webcam
Convert the positive.idx into a VEC file:
NB: here you need to set a width and height for the normalized detection size
(so like in doing this, you are basically setting the aspect ratio of the detector -- ie it will be able to detect objects at various sizes, but always in the ratio of width to height determined here)
opencv_createsamples -vec saski.vec -info saski.idx -w 10 -h 30
Show the samples ...
So here you can scale the size to be larger (but width and height need to be in the same ratio... so for instance you can add a 0 to scale up by 10)
Training command
opencv_haartraining -data bottle_classifier -vec saski.vec -w 23 -h 73 -bg non-saski.idx -nstages 20 -nsplits 1 -minhitrate 0.998 -maxfalsealarm 0.5
ERRORS
when the -w and -h mismatch (from creating the vec file to training with it)
what(): /build/opencv-FWWjHr/opencv-2.4.9.1+dfsg/apps/haartraining/cvhaartraining.cpp:1936: error: (-2) Vec file sample size mismatch in function icvGetHaarTrainingDataFromVec
References
Eigenfaces:
http://cognitrn.psych.indiana.edu/nsfgrant/FaceMachine/faceMachine.html
Performance
Simulating decision trees
Questionnaire with simple questions.
BUILDING OPENCV with Multiprocessor support
Download the source ( http://opencv.org/downloads.html )
get prereqs
- sudo apt-get install build-essential
- sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
- sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
unzip the folder
- cd opencv-2.4.13
- mkdir build
- cd build
- cmake -D WITH_OPENMP=ON ..
(actually after a compile error that seemed due to conflict with by built in ffmpeg, I used)
- cmake -D WITH_OPENMP=ON -D WITH_FFMPEG=0 ..
then
Command that got stuck building stage 3...
- opencv_traincascade -data test_cascade -vec test.vec -w 23 -h 73 -bg non.bottle.idx -nstages 5 -nsplits 1 -minhitrate 0.998 -maxfalsealarm 0.5 -numPos 3
Tutorials
https://www.youtube.com/watch?v=jG3bu0tjFbk&index=17&list=PLQVvvaa0QuDdttJXlLtAJxJetJcqmqlQq