azach
azach

Reputation: 99

OpenCV(3.4.1) Error: Assertion failed (_img.rows * _img.cols == vecSize)

I tried to run opencv_traincascade in cmd, but it crashes instantly and gives that output.

opencv_traincascade -data data -vec pos.vec -bg neg.lst -numPos 31 -numNeg 
100 -numStages 10 -w 20 -h 20 
PARAMETERS:
cascadeDirName: data
vecFileName: pos.vec
bgFileName: neg.lst
numPos: 31
numNeg: 100
numStages: 10
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 20
sampleHeight: 20
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
Number of unique features given windowSize [20,20] : 78460

And here is the error message:

===== TRAINING 0-stage =====
<BEGIN
OpenCV(3.4.1) Error: Assertion failed (_img.rows * _img.cols == vecSize) in 
CvCascadeImageReader::PosReader::get, file C:\build\master_winpack-build- 
win64- 
vc15\opencv\apps\traincascade\imagestorage.cpp, line 153

I tried deleting all opencv xml as it was suggested else where, another reason for this problem to occure seams to be, that -w 20 - h 20 doesnt match the size of images.Therefore I doubled checked that, too.

A blind guess that may cause some issues is that the path "C:\build\master_winpack-build-win64-vc15\opencv\apps\traincascade" is correct. The imagesstorage.cpp is located in C:\Users\azach\Downloads\opencv\sources\apps\traincascade

Upvotes: 3

Views: 1612

Answers (2)

David R.G
David R.G

Reputation: 11

I got this issue because I forgot to delete a previous cascade classifier file.

Upvotes: 1

user14678939
user14678939

Reputation: 327

For me, the issue was that when I used opencv_createsamples to create the .vec file in a previous step, I used different -w and -h arguments than those I used for opencv_traincascade. All I had to do to fix the issue was redo opencv_createsamples and opencv_traincascade with consistent width and heights.

Upvotes: 1

Related Questions