|
4 | 4 |
|
5 | 5 | 1. Get OpenCV
|
6 | 6 |
|
7 |
| - brew tap homebrew/science |
8 |
| - brew install --with-tbb opencv |
| 7 | + brew tap homebrew/science |
| 8 | + brew install --with-tbb opencv |
9 | 9 |
|
10 | 10 | 2. Clone this repository
|
11 | 11 |
|
12 |
| - git clone https://github.com/mrnugget/opencv-haar-classifier-training |
| 12 | + git clone https://github.com/mrnugget/opencv-haar-classifier-training |
13 | 13 |
|
14 | 14 | 3. Put your positive images in the `./positive_images` folder and create a list
|
15 | 15 | of them:
|
16 | 16 |
|
17 |
| - find ./positive_images -iname "*.jpg" > positives.txt |
| 17 | + find ./positive_images -iname "*.jpg" > positives.txt |
18 | 18 |
|
19 | 19 | 4. Put the negative images in the `./negative_images` folder and create a list of them:
|
20 | 20 |
|
21 |
| - find ./negative_images -iname "*.jpg" > negatives.txt |
| 21 | + find ./negative_images -iname "*.jpg" > negatives.txt |
22 | 22 |
|
23 | 23 | 5. Create positive samples with the `bin/createsamples.pl` script and save them
|
24 | 24 | to the `./samples` folder:
|
25 | 25 |
|
26 |
| - perl bin/createsamples.pl positives.txt negatives.txt samples 1500\ |
27 |
| - "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\ |
28 |
| - -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40" |
| 26 | + perl bin/createsamples.pl positives.txt negatives.txt samples 1500\ |
| 27 | + "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\ |
| 28 | + -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40" |
29 | 29 |
|
30 | 30 | 6. Compile the `mergevec.cpp` file in the `./src` directory:
|
31 | 31 |
|
32 |
| - cp src/mergevec.cpp ~/opencv-2.4.6/apps/haartraining |
33 |
| - cd ~/opencv-2.4.6/apps/haartraining |
34 |
| - g++ `pkg-config --libs --cflags opencv` -I. -o mergevec mergevec.cpp\ |
35 |
| - cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp\ |
36 |
| - cvhaartraining.cpp |
| 32 | + cp src/mergevec.cpp ~/opencv-2.4.6/apps/haartraining |
| 33 | + cd ~/opencv-2.4.6/apps/haartraining |
| 34 | + g++ `pkg-config --libs --cflags opencv` -I. -o mergevec mergevec.cpp\ |
| 35 | + cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp\ |
| 36 | + cvhaartraining.cpp |
37 | 37 |
|
38 | 38 | 7. Use the compiled executable `mergevec` to merge the samples in `./samples`
|
39 | 39 | into one file:
|
40 | 40 |
|
41 |
| - find ./samples -name '*.vec' > samples.txt |
42 |
| - ./mergevec samples.txt samples.vec |
| 41 | + find ./samples -name '*.vec' > samples.txt |
| 42 | + ./mergevec samples.txt samples.vec |
43 | 43 |
|
44 | 44 | 8. Start training the classifier with `opencv_traincascade`, which comes with
|
45 | 45 | OpenCV, and save the results to `./classifier`:
|
46 | 46 |
|
47 |
| - opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\ |
48 |
| - -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\ |
49 |
| - -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\ |
50 |
| - -precalcIdxBufSize 1024 |
| 47 | + opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\ |
| 48 | + -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\ |
| 49 | + -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\ |
| 50 | + -precalcIdxBufSize 1024 |
51 | 51 |
|
52 | 52 | 9. Wait until the process is finished (which takes a long time — a couple of
|
53 | 53 | days probably, depending on the computer you have and how big your images are).
|
54 | 54 |
|
55 | 55 | 10. Use your finished classifier!
|
56 | 56 |
|
57 |
| - cd ~/opencv-2.4.5/samples/c |
58 |
| - chmod +x build_all.sh |
59 |
| - ./build_all.sh |
60 |
| - ./facedetect --cascade="~/finished_classifier.xml" |
| 57 | + cd ~/opencv-2.4.5/samples/c |
| 58 | + chmod +x build_all.sh |
| 59 | + ./build_all.sh |
| 60 | + ./facedetect --cascade="~/finished_classifier.xml" |
61 | 61 |
|
62 | 62 |
|
63 | 63 | ## Acknowledgements
|
|
0 commit comments