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?
So I've been trying to run the command
opencv_traincascade -data HandsData -vec hands.vec -bg HandsNeg.txt -numPos 3641 -numNeg 2578 -numStages 20 -w 27 -h 48 -mode ALL -minHitRate 0.999 -maxFalseAlarmRate 0.5 -precalcValBufSize 1024 -precalcIdxBufSize 1024
and I get the error
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 3641 : 3641
OpenCV Error: Assertion failed (_img.cols == winSize.width) in get, file /builddir/build/BUILD/OpenCV-2.0.0/apps/traincascade/imagestorage.cpp, line 86
terminate called after throwing an instance of 'cv::Exception'
Aborted
I've seen suggestions around to change the positive image number, where I use 1043 instead and still get the same error. Then I also see suggestions of editing the source code. The problem is that I built OpenCV with yum and would like to not have to rebuild from source.
sudo find / -name imagestorage.cpp
turns up nothing.
I'm at a complete loss of what to do.
Additional info: Steps I took to get to this point
I created everything from some videos using ffmpeg. These were from a phone and VLC lists the info as
Resolution: 1920x1090
Display resolution: 1920x1080
The ffmpeg command was (replacing input/output with respective videos and locations)
steven ~/computer_vision $ ffmpeg -i videos/Not\ hands\ stuff.mp4 -y -r 40 -s 27x48 -f image2 NotHandsorFists/Negs-%4d.png
Files in Hands.txt are of the form
steven ~/computer_vision $ cat Hands.txt | head -n 1
Hands/LeftHand-0001.png 1 0 0 27 48
I compiled the vec file with
steven ~/computer_vision $ opencv_createsamples -info Hands.txt -num 3641 -w 27 -h 48 -vec hands.vec
The negative file is in the form
steven ~/computer_vision $ cat HandsNeg.txt | head -n 1
Fists/LeftFist-0001.png
and the working directory is
steven ~/computer_vision $ ls
Fists fists.txt Hands HandsData HandsNeg.txt Hands.txt hands.vec NotHandsorFists NotHandsorFists.txt videos
Edit:
I've tried changing png to jpg and bmp to get rid of the channels. No help.
when I call the opencv_traincascade, I get the error message:
Training parameters are loaded from the parameter file in data folder!
Please empty the data folder if you want to use your own set of parameters.
And my call command is:opencv_traincascade.exe -data datatrain -vec pos\pos.vec -bg neg\neg.dat -numPos 3424 -numNeg 3900 -numStages 16 -w 64 -h 64 -minHitRate 0.9999 -maxFalseAlarmRate 0.5 -mode All
What does that mean? How can I fix it?
Thank you!
Problem disappeared for me when I recreated the folder in another computer with a slightly different image set. Then I copied the files back to my computer.
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