I'm using opencv-3.3.1 on windows. I have a 'pos' file containing my positive images and a file called 'info.txt' which contains the address, number and the coordinates of object in positive images.
In order to make a .vec file I use this command:
opencv_createsamples -info info.txt -num 1000 -w 100 -h 100 -vec car.vec
To test the vec file I use this command:
opencv_createsamples -w 100 -h 100 -vec car.vec
But the output of the command is not correct it's look like that the coordinates in vec file isn't correct. I have checked the info file several times and it is accurate.(but I have tried it on Linux Ubuntu too)
Here is my info.txt file:
pos/1.jpg 1 80 146 164 163
.....
.....
The question is why the output isn't correct while the coordinates are true or how can I fix it?
I am using open CV library, I have created positive image folder and negative image folder, text file has also been created which contains the path of images in the folder, following this link http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html
when i am trying to run the command
perl bin/createsamples.pl positives.txt negatives.txt samples 7 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"
but nothing is created in samples folder as you can see in the screenshot. Can anybody help me?
screenshot available here
Try using this command:
perl bin/createsamples.pl positives.txt negatives.txt ./samples 1500\
"opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"
Just added ./ before samples as it was not getting the exact directory where to store .vec files.
I am trying to train a cascade classifier using OpenCV, a tutorial & UIUC Image Database for Car Detection. However, the training 'hangs' at stage 0 and never generates any files; in the tutorial, results are seen in a matter of minutes.
I am running OpenCV 2.4.8, which I have installed using conda, on a 2015 MBP running Yosemite (10.10.5)
Steps:
Downloaded the dataset & saved the positive images in a pos folder and the negative images in a neg folder
generated a txt file for the positive images
find pos -iname "*.pgm" > cars.txt
sed -i '' 's/.pgm/.pgm 1 0 0 100 40/g' cars.txt
generated a txt file for the negative images
find neg -iname "*.pgm" > bg.txt
generated a vec file from cars.txt
opencv_createsamples -info cars.txt -num 550 -w 48 -h 24 -vec cars.vec
create a data dir
mkdir data
train cascade
opencv_traincascade -data data -vec cars.vec -bg bg.txt -numPos 500 -numNeg 500 -numStages 2 -w 48 -h 24 -featureType LBP
Output:
PARAMETERS:
cascadeDirName: data
vecFileName: cars.vec
bgFileName: bg.txt
numPos: 500
numNeg: 500
numStages: 2
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 48
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 500 : 500
NEG count : acceptanceRatio 500 : 1
I have waited for several hours but the training never progresses nor does it generate any files in my data directory. What is causing the 'hanging'?
For what it's worth, I ran into the same symptom and it was driving me crazy. Uninstalling and reinstalling opencv fixed it. The exact command that was hanging suddenly worked fine. It could be you have an old version of opencv lingering somewhere like I had:
$ brew uninstall opencv
Uninstalling /usr/local/Cellar/opencv/2.4.12... (225 files, 36M)
opencv 2.4.11_1 is still installed.
Remove them all with `brew uninstall --force opencv`.
$ brew uninstall --force opencv
Uninstalling opencv... (222 files, 35M)
$ brew install opencv --with-tbb
At any rate, something to consider.
I run into the same problem. It turns out using haar cascade training works just fine. You could specific more stages for it to improve accuracy.
I just don't see how you expect to get anything good out of two training stages. You should train until your -acceptanceRatioBreakValue reaches 10e-5. You've ordered 10 burgers from OpenCV but left after only getting 2.
See here: http://docs.opencv.org/3.1.0/dc/d88/tutorial_traincascade.html#gsc.tab=0
Compiling OpenCV with --use-tbb (from homebrew) solved this for me, I believe it is a bug with GCD implementation on OS X as mentioned here: https://github.com/opencv/opencv/issues/4765
I'm using this tutorial, and I'm on the stage of creating lots of samples from my positive images. I'm using Windows.
This is the command:
perl bin/createsamples.pl positives.txt negatives.txt samples 1500\ "C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -maxxangle 1.1\ -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"
And this is what I get as output, for each of the positive images:
C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -max
xangle 1.1\ -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img 60inclin
ation_315azimuth.jpg -bg tmp -vec samples0inclination_315azimuth.jpg.vec -num 62
Info file name: (NULL)
Img file name: 60inclination_315azimuth.jpg
Vec file name: samples0inclination_315azimuth.jpg.vec
BG file name: tmp
Num: 62
BG color: 0
BG threshold: 0
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 80
Height: 40
Create training samples from single image applying distortions...
Done
The messages seemed successful so I went into the samples folder expecting to see 1500 samples, but there's nothing there! I noticed the info file is <NULL>, does that have anything to do with this? There doesn't seem to be any error, what went wrong?
Edit
I've changed the command to include absolute paths for everything, eg
perl bin/createsamples.pl C:\my_work\code\opencv-haar-classifier-training-master\positive_images\ C:\my_work\code\opencv-haar-classifier-training-master\positive_images\ samples 1500\ "C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -maxxangle 1.1\ -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"
But still no luck!
I had a similar problem I'll try to explain what I did, I hope it will solve you problem.
First of all the NULL after -info is normal. As said in the official documentation of OpenCV for opencv_createcamples you need to either input an image (-img) or a collection of images (-info) I'll let you read the documentation for further understanding, but for this example you don't need it.
Secondly you don't need to put absolute paths in this command; here is my command:
perl bin/createsamples.pl positives.txt negatives.txt samples 1500 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 -maxzangle 0.5 -maxidev 40 -w 42 -h 40"
to do this be sure to be at the root of the gitHub directory you have download (the parent one of bin) be sure that your positives.txt and negatives. txt are in this directory. Also copy paste the opencv_createsamples.exe from OpenCV directory in this one.
This done I'll now explain the main problems: The project was developped for Ubuntu at the beginning so it works for mac easily but I think you must be under Windows. If you hadn't already please download Cygwin because it uses mainly Linux commands.
As I said I was blocked with a similar problem, so I tried to use opencv_createsample directly instead of the perl script to see if the problem was coming from there and I noticed that the problem was coming from the fact that my positives.txt and negatives.txt were under Windows format and not Unix so the Perl script wasn't able to read them properly.
The difference between windows and linux are big and Cygwin doesn't bridge the gap so there might be other encoding problems. So what I did is surely not the fastest way to resolve the problem, but it is an easy one.
I just installed an Ubuntu vm on my PC
Installed Opencv with TBB ( a lot of tutorials internet, the best is the one from the OpenCV site).
I Downloaded the gitHub Classifier training and then I followed the commands given and it worked well.
Another simpler explanation. Let's say you are new to OpenCV (as I am), and you're just following one of the tutorial videos, to create your first object detector. You might have created a sample image by cut-pasting from the web. Sample images must be monochrome, but more than that, they must be single-channel, 8-bit monochrome. If you photoshopped your sample to appear monochrome, but didn't change its channel configuration, opencv_createsamples will ignore it if it actually has more than one channel.
Source: ~/apps/createsamples/utilities.cpp, function icvStartSampleDistortion().
I was presented with a similar problem, also in Windows, but my solution was to check positives.txt and negatives.txt were in a format the the createsamples.pl file could understand. I'm not sure this was the same as your problem, but I ended up here so others might too.
I ran the following python script from the same directory as createsamples.pl to form the text files, which seemed to make the perl file work for me:
'''
Run this from the folder containing the positive and negative samples' folders (Note: outputs the text files to this directory)
'''
import glob
import sys
def write_locations(folder, textFile):
print('')
file = open(textFile, 'w')
for contents in glob.glob('{}/*'.format(folder)):
try:
fileName = contents.split("\\")[-1]
file.write('\n./{0}/{1}'.format(folder, fileName))
print('./{0}/{1}'.format(folder, fileName))
except:
pass
write_locations('positive', 'positives.txt')
write_locations('negative', 'negatives.txt')
print('\n -Done.')
The organisation of my folders might be slightly different to the tutorial (I only went there for the perl file), but all I'm doing is checking that the text files read something like:
./positive/1_1.png
./positive/1_2.png
./positive/1_3.png
./positive/1_4.png
and so on.
I had a similar problem I'll try to explain what I did, I hope it will solve your problem.
First, name the files positives.dat and negatives.dat instead of positives.txt and negatives.txt.
Second, copy and paste positives.dat and negatives.dat files into the current directory, then run:
perl bin/createsamples.pl positives.dat negatives.dat samples 1000 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"
After that, check your samples folder, and you should see the positive & negative folders containing many vector files.
I had the same problem. The problem was that I had Captital letters in the filename, but not in the terminal code.
This should work:
perl bin/createsamples.pl positives.txt negatives.txt samples 3000 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 0 -maxyangle 0 maxzangle 0 -maxidev 40 -w 32 -h 32"
I want to train haar cascade by opencv_traincascade.
after
opencv_traincascade -data result/apple/ -vec samples/sample.vec -bg negatives.dat -minHitRate 0.999 -mode ALL -numPos 2000 -numNeg 1500 -precalcValBufSize 2000 -precalcIdxBufSize 2000
I saw that only one core is loaded. What can I do to quickly train the cascade? If I need to recompile OpenCV with some options please show me how to do it. Thank you!
UPD:
Found this thread. There is a new question: how to set up OpenCV with flag HAVE_TBB? And will it help me? Which version of IPP I can use with OpenCV 2.4.3?
Sorry for my English.
I found the answer to my question.
Tested on xubuntu 12-10 with IPP 7.1 for intel64 and Opencv 2.4.3
To use IPP&&TBB with OpenCV you should download and install them from the official site
ia32 for 32-bit architecture, intel64 for 64 bit!
After you should compile OpenCv by this command:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D WITH_IPP=ON -D IPP_H_PATH=/opt/intel/ipp/include/ -D WITH_TBB=ON ..
Check output after cmake!
make
sudo make install