Ask Your Question
0

Haar Training: error (-215)_img.row * _img.cols == vecSize in function get

asked 2015-01-05 21:24:17 -0600

dylan7 gravatar image

Hello,

This issue was already discussed on this forum. However, I believe it was not solved, and I have already searched the internet for a solution and cannot find one.

I am trying to train a Haar Cascade to detect hands. I have a vec file of size 1000. I have 50 positive images and 600 negative images. I have tried both dropping my positive images and negative images. When I run the following command I receive the following error:

opencv_traincascade -data classifier -data classifier -vec samples.vec -bg negatives.txt
-numstages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\ -numNeg 600 -w 80
-h 40 -mode ALL -precalcValBufSize 1024\ -precalcIdxBufSize 1024

PARAMETERS:
cascadeDirName: classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 1000
numNeg: 1000
numStages: 20
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC



===== TRAINING 0-stage =====
<BEGIN
OpenCV Error: Assertion failed (_img.rows * _img.cols == vecSize) in get, file /home/lie/Desktop/Install-OpenCV-master/Ubuntu/2.4/OpenCV/opencv-2.4.9/apps/traincascade/imagestorage.cpp, line 157
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/lie/Desktop/Install-OpenCV-master/Ubuntu/2.4/OpenCV/opencv-2.4.9/apps/traincascade/imagestorage.cpp:157: error: (-215) _img.rows * _img.cols == vecSize in function get

Aborted (core dumped)

I tried lowering my positive count, lowing the negative count, and doing the whole process over again and still received the same error. I have located the error in the cpp code, but I do not know how to recompile the code to print out the values that are causing the error. Any suggestions?

By the way: I am following the tutorial at : http://coding-robin.de/2013/07/22/tra...

Thank you

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-01-06 06:29:35 -0600

First of all your command is full of typos and abundant slashes. It should be

opencv_traincascade -data classifier/ -vec samples.vec -bg negatives.txt -numstages 20 -minHitRate 0.999 -numPos 1000 -numNeg 600 -maxFalseAlarmRate 0.5 -w 80 -h 40 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

Secondly, if you have a vec file of 1000 elements but only 50 positive images, can you give the command on how you created the vector? As far as I see this is not possible unless you used the warping functions which is a very bad approach. Also keep in mind that the algorithm can reject positives so it will probably fail anyway in the second or third stage.

Also negative images can contain multiple image patches size of your model. So basically you can ask for more patches than there are images.

I suggest changing the command to the following, if your vector data is correct.

opencv_traincascade -data classifier/ -vec samples.vec -bg negatives.txt -numstages 20 -minHitRate 0.999 -numPos 850 -numNeg 2000 -maxFalseAlarmRate 0.5 -w 80 -h 40 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

But keeping a minHitRate of 0.999 will be quite difficult. That allows almost no misclassification!

edit flag offensive delete link more

Comments

Thank you for responding. I ended up actually figuring out this error. It was the fact that sampleWidth and sampleHeight were 24 ( as can be seem in the error statement above), but I was giving it 80 and 40. Which makes it seem like 24x24 is some sort of vector size default? However, I would still like to know how I can improve my training performance. To answer your question I am using a famous perl script called createsamples.pl by Naotoshi Seo.This mixes the positive and negatives and does apply warping. However, for some reason no matter how many images I have, it only creates 1000 vecs. This is the only way I know how to create vector files. Is there an alternative to this? What is a better minHitRate? These are all parameters from a tutorial.Thank you again.

dylan7 gravatar imagedylan7 ( 2015-01-11 17:17:17 -0600 )edit

This is my latest command of how I created my vectors:

perl bin/createsamples.pl positives.txt negatives.txt samples/ 7000 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\ -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 24 -h 24"

Although it only creates 1000vecs even though I specified 7000, and might have some unnecessary slashes.

dylan7 gravatar imagedylan7 ( 2015-01-11 17:24:00 -0600 )edit
1

AHA I know your problem. -w and -h parameters are defined at the time you are creating your sample set. If you set then 24x24 there, then do not expect your training to work with 80x40. Those dimensions need to match exactly since they define how your training setup runs through the data vector. Also, that script is the worst script ever, it makes absolutely NO sense to combine positive and negative training samples into a single training vector ... no idea where that dude got the inspiration ... the 1000 is a parameter in the createsamples interface. Use the C++ version from the OpenCV repo and not that perl script.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-12 02:37:49 -0600 )edit

Thank you for your help. Strangely, even when I used -w 80 -h 40 for the pearl script and used -w 80 -h 40 on traincascade I still got the error. Using 24 x 24 works now, but it seemed as if 24x 24 was some sort of default? I don't know if matters much since I won't be using that pearl script again, but it seemed as if traincascade required 24x24 vec samples. So for using the C++ version I've read that I have to create .dat file with the location of the image of interest next to the name of the pic. Is there any fast way to get the location of the image of interest from every single positive pic, or should I just choose pics with similar locations of the object of interest and use the same description for every positive?

dylan7 gravatar imagedylan7 ( 2015-01-12 12:49:20 -0600 )edit

Probably the perl script doesnt overwrite the parameter and simply takes default value. As for the locations, you will need to use an annotation tool to store and record all locations. Object detection is a hell of a work :P

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-12 12:57:08 -0600 )edit

ok, thank you very much

dylan7 gravatar imagedylan7 ( 2015-01-12 12:59:15 -0600 )edit

I have another question if you don't mind. When I tried doing

opencv_createsamples -info positives.dat -vec samples.vec -num 2387 -w 24 -h 24

I had 2387 positive images, I know I probably need more, but the issue is I still only got 1000 samples in the vec file

   Info file name: (NULL)
Img file name: (NULL)
Vec file name: samples.vec
BG  file name: (NULL)
Num: 1000
BG color: 0
BG threshold: 80
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: 24
Height: 24
dylan7 gravatar imagedylan7 ( 2015-01-12 20:00:38 -0600 )edit

Are you sure that positives.dat lists more than 1000 items?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-13 03:12:54 -0600 )edit

When I scroll to the bottom it says line 2387, which is how many positives I have .

dylan7 gravatar imagedylan7 ( 2015-01-13 12:29:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-05 21:23:45 -0600

Seen: 5,207 times

Last updated: Jan 06 '15