opencv_traincascade.exe error, where is the parameter folder? - opencv

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.

Related

opencv_createsamples doesn't work correctly

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?

createsample.exe crashes every time

Hi I am trying to create samples using opencv_createsamples.exe but it crashes every time. I've checked different builds, opencv2 and opencv3. I don't know how to overcome this. My command looks like this
opencv_createsamples.exe -img C:/Users/dpach/Pictures/Interfejsy/img/1.jpg -maxxangle 15 -maxyangle 15 -maxzangle 1 -w 80 -h 40 -vec test.vec -bgtresh 0 -bgcolor 0 -show
The windows to show samples is opening but after that I receive info that program is not responding. Any ideas ?
// EDIT
I've tried to start it from a pseudo unix bash and I receive then Segmentation fault
// EDIT2
It crush after that Create training samples from single image applying distortions...

OpenCV: training a cascade classifier

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

OpenCV Error: Assertion failed (_img.cols == winSize.width)

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.

opencv createsamples has no error, but no samples found

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"

Resources