Ask Your Question
2

opencv_traincascade error : _img.rows * _img.cols == vecSize

asked 2014-08-09 21:00:27 -0600

andonios gravatar image

updated 2014-08-10 02:09:09 -0600

berak gravatar image

Hi All,

I'm trying to get a basic version of a cascade classifier working with my own data.

Here's what I've done:

1) Created a few samples (which runs without errors). opencv_createsamples -info C:\Users\anthony\Dropbox\CASEY\training_images\info.txt -vec C:\Users\anthony\Dropbox\CASEY\training2.vec -bg C:\Users\anthony\Dropbox\CASEY\training_images\bg.txt -num 24 -bgcolor 0 -bgthresh 0 -maxxangle 0.3 -maxyangle 0.3 maxzangle 0.5 -maxidev 40 -w 24-h 24

The BG file contains 10 image paths: false/fake_teapot.jpg ... ..

2) When Attempting to train with the following command I get the error shown after: opencv_traincascade -data C:\Users\anthony\Dropbox\CASEY -vec C:\Users\anthony\Dropbox\CASEY\training2.vec -bg C:\Users\anthony\Dropbox\CASEY\training_images\bg.txt -numPos 24 -numNeg 10 -sampleWidth 24 -sampleHeight 24

-- ERROR OpenCV Error: Assertion failed (_img.rows * _img.cols == vecSize) in CvCascadeImageReader::PosReader::get, file ........\opencv\apps\traincascade\imagestorage.cpp, line 157

I'm adjusting the parameters and still getting the same error. I presume this is a check done early on for something I've seriously missed but I really can't figure out what. I have the same number of images, same image widths/height for both positive and negative and for both commands.

Any directions or help as I can see very little on Google and the documentation I've found just lists parameters with descriptions.

Thanks.

edit retag flag offensive close merge delete

Comments

What I believe is that opencv_traincascade has no parameter named -sampleWidth, I guess we mention it by -w, same goes with the height. Please try this, if the problem still persists, do ping me up here.

Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-08-10 04:18:55 -0600 )edit

Is your command line for opencv_createsamples (as pasted) missing a space before -h? "-w 24-h 24" Finally you can look at your resulting vec file to see if it contains the data you expect. opencv_createsamples -vec C:\Users\anthony\Dropbox\CASEY\training2.vec -view If it doesn't, you need to fix that before running opencv_traincascade

Netsai Chibuku gravatar imageNetsai Chibuku ( 2014-08-29 02:38:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-10-26 23:19:49 -0600

kukuruza gravatar image

updated 2014-10-26 23:20:16 -0600

I hope andonios figured it out (after inserting the missing space before "-h"). I had the same issue, and my problem was with backup files of opencv_traincascade and with varying sample size.

opencv_traincascade saves additional .xml files "for the case of interrupted training". First, I created a .vec file using one pair of values for sample size and trained the model. Then I decided to use a different sample size. If I didn't remove the opencv .xml backup files, opencv_traincascade would throw the error described in the question. I guess, because it decides to load those files if they exist.

If this your case, simply deleting all opencv .xml files before another training should help.

edit flag offensive delete link more

Comments

Exactly the problem and correct solution!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-28 06:01:12 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-09 21:00:27 -0600

Seen: 5,866 times

Last updated: Oct 26 '14