Troubles on training Haar cascade with LBP - c++

I'm trying to train some branch logos with haar_cascade. What I've done is, I've taken 2500 squared pictures of 500 x 500 to populate the samples for opencv_createsamples. Then I generate them as:
opencv_createsamples -info 'logo.info' -vec '../logo.vec' -bg '../Negatives/bg.txt' -w 24 -h 24 -num 2500
in my logo.info I've got lines which correspond to the relative path of every picture, with a 1 0 0 500 500 meaning "there's one object between (0,0) and (500, 500)"
then I train the cascade as:
opencv_traincascade -data 'cascade/' -vec '../logo.vec' -bg '../Negatives/bg.txt' -numPos 2500 -numNeg 3019 -numStages 25 -featureType LBP -w 24 -h 24
with these parameters:
PARAMETERS:
cascadeDirName: cascade/
vecFileName: ../logo.vec
bgFileName: ../Negatives/bg.txt
numPos: 2500
numNeg: 3019
numStages: 25
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
And I've got 2 kind of errors:
OpenCV Error: One of arguments' values is out of range (No components/input_variables is selected!) in cvPreprocessIndexArray, file /tmp/buildd/opencv-2.3.1/modules/ml/src/inner_functions.cpp, line 432
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/opencv-2.3.1/modules/ml/src/inner_functions.cpp:432: error: (-211) No components/input_variables is selected! in function cvPreprocessIndexArray
...
this errors uses to happen when you don't give a significant difference between your num of images and your -num parameter. So, let's try to give less 100!!
well, when I've adjusted the parameters to not to go out from the array, I get the same type of output than images, but I get this error:
OpenCV Error: Assertion failed (tempNode->left) in write, file /tmp/buildd/opencv-2.3.1/modules/traincascade/boost.cpp, line 628
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/opencv-2.3.1/modules/traincascade/boost.cpp:628: error: (-215) tempNode->left in function write
Aborted
I've tried:
Changing the destiny size of the images (24x24, 36x36...)
Changing the -mode parameter.
Trying to put a #positiveSamples < #negativeSamples and #positiveSamples > #negativeSamples
What I have to do, is training obligatory with LBP (not HAAR). Do anyone have any clue?
Thank you in advance.

Uninstalling and rebuilding OpenCV solved the problem.

Related

OpenCV Camera Calibration tutorial crashes

By following this tutorial:
I created an XML configuration file, and a list of asymmetric circle grid images to run the camera calibration C++ sample. Everything is checked in here.
When I set board width to 5 and height to 4 I get this error:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.0-dev) /home/zero/opencv-master/modules/core/src/convert_c.cpp:112: error: (-215:Assertion failed) src.size == dst.size && src.channels() == dst.channels() in function 'cvConvertScale'
All the images are exactly the same, taken using Raspberri Pi camera in a sequence.
When I set board width to 4 and height to 3, I get this instead:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.0-dev) /home/zero/opencv-master/modules/calib3d/src/circlesgrid.cpp:1524: error: (-215:Assertion failed) h >= 2 && w >= 2 in function 'getCornerSegments'
Has anyone gotten this sample to work, or is it hopelessly broken? Someone created the same issue in OpenCV but it was never resolved:
https://github.com/opencv/opencv/issues/6503
The issue I linked in the original post was actually resolved some time later and contains the solution:
https://github.com/opencv/opencv/issues/6503
Run is OK if set config size_width and size_height with n - 1 and m - 1(n is number of columns in real board-size, m is number of rows in real board-size)
The issue was that width and height were not counted the way I assumed (unfortunately it was not clear from documentation how they were counted).
Apologies to everyone who commented!

Can not use -w -h in traincascade

I have sone problem with size of sample traincascade. I use opencv_traincascade.exe to train rear of car. Size of rear of car which i need to have a size 72x48. Now i use createsample to create 2000 sample size 72x48 with command
D:\Project_Android\Classifier\bin\opencv_createsamples.exe -info positive.txt -bg negative.txt -vec vector.vec -num 2000 -w 72 -h 48
Now, i have a vector file and negative.txt (sure negative.txt have absolute direction to background images). i use opencv_traincascade.exe with command.
D:\Project_Android\Classifier\bin\opencv_traincascade.exe -data HaarTraining -vec vector.vec -bg negative.txt -numPos 250 -numNeg 1500 -numStages 10 -nonsym -minhitrate 0.999 -maxfalsealarm 0.5 -mode ALL -w 72 -h 48 -precalcValBufSize 2046 -precalcIdxBufSize 2046 PAUSE
I get an error.
When i use size 24x24 (-w 24 -h 24) for createsample.exe step and cascadetraining step, everything is ok, traincasecade is run.
it seem to be size 24x24 is a default size of sample and it still remain. and i seem to be cannot config it in file .bat (i write command in file bat and click file bat to run)
And one thing i see in command window in above picture that: -precalcValBufSize and -precalcIdxBufSize still remain default value 1024. No change with -w -h -precalcValBufSize -precalcIdxBufSize.
So what problem with it, i don't understand why don't i choose size of sample for train. I just can use size 24x24, all size other always give error "Assertion failed <_img.row*_img.height == vecSize> in CvcascadeImageReader...pla pla"
Please help me to solve this problem. So many thank to you

Out of memory opencv haartraining

I have 30 positive images and 60 negatives images.
When I tried to execute the haartraining with 4GB of memory and Quadcore processor machine, I get this error message:
OpenCV ERROR: Insufficient memory (Out of memory)
in function cvAlloc, cxalloc.cpp(111)
Terminating the application...
called from cvUnregisterType, cxpersistence.cpp(4933)
The command is:
./opencv-haartraining -vec vector/myvector.vec -bg negatives.txt -npos 24 -nneg 55 -mem 2048 -mode ALL -w 86 -h 150
The computer has only 765 MB used, but the process exceeds the given limit, and uses a lot of memory in swap until the overflow occurs. Any suggestions of what can be done to solve this problem?
Regards
Maybe your "myvector.vec" is too big. All these pictures are loaded to RAM.
Try to resize the images.

Callgrind Profile Format inclusive/self cost

I'm trying to understand the Callgrind Profile Format. I found the online description
I thought I understood it fairly well until I encountered the 'Extended Example':
events: Instructions
fl=file1.c
fn=main
16 20
cfn=func1
calls=1 50
16 400
cfl=file2.c
cfn=func2
calls=3 20
16 400
fn=func1
51 100
cfl=file2.c
cfn=func2
calls=2 20
51 300
fl=file2.c
fn=func2
20 700
The description reads: One can see that in "main" only code from line 16 is executed where also the other functions are called. Inclusive cost of "main" is 420, which is the sum of self cost 20 and costs spent in the calls.
How can the inclusive cost of 'main' be 420, when the self cost of only func2 is already 700?
OK, the description is wrong: when i paste this example and open it in kcachegrind, indeed it shows a total inclusive cost of 820. That makes sense. Sorry for the noise.

haar training OpenCV assertion failed

I am trying to train a haar-like classifier for pedestrians in OpenCV using 3340 positive images and 1224 negative images. (in a .txt file I keep the negative image names i.e negatives(1).bmp, and in a txt file I keep the positives i.e. picture(1).bmp 1 0 0 64 128.
Actually positive examples are already cropped images of pedestrians so I only need specify one positive sample per image).
At some point during the training process it stops and says :
"Opencv Error: Assertion failed (elements_read==1)in unknown function, file c:\path\cvhaartraining.cpp, line 1858"
Any ideas as to what is causing this ?
this issue was answered by creater of the utility on the OpenCV DevZone site in June 2012.
To quote Maria:
The problem is that your vec-file has exactly the same samples count
that you passed in command line -numPos 979. Training application used
all samples from the vec-file to train 0-stage and it can not get new
positive samples for the next stage training because vec-file is over.
The bug of traincascade is that it had assert() in such cases, but it
has to throw an exception with error message for a user. It was fixed
in r8913.
-numPose is a samples count that is used to train each stage. Some already used samples can be filtered by each previous stage (ie
recognized as background), but no more than (1 - minHitRate) * numPose
on each stage. So vec-file has to contain >= (numPose + (numStages-1)
* (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file that can be recognized as background right away. I hope it
can help you to create vec-file of correct size and chose right numPos
value.
It worked for me. I also had same problem, I was following the famous tutorial on HAAR training but wanted to try the newer training utility with
-npos 7000 -nneg 2973
so i did following calcs:
vec-file has to contain >= (numPos + (numStages-1) * (1 - minHitRate) * numPos) + S
7000 >= (numPos + (20-1) * (1 - 0.999) * numPos) + 2973
(7000 - 2973)/(1 + 19*0.001) >= numPos
numPos <= 4027/1.019
numPos <= 3951 ~~ 3950
and used:
-npos 3950 -nneg 2973
It works. I also noticed that others have also had success with reducing numPos : here