我一直收到此错误
OpenCV Error: Assertion failed (_img.rows * _img.cols == vecSize) in get, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp, line 157
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp:157: error: (-215) _img.rows * _img.cols == vecSize in function get
Aborted (core dumped)
opencv_traincascade
时。我使用这些参数运行:opencv_traincascade -data data -vec positives.vec -bg bg.txt -numPos 1600 -numNeg 800 -numStages 10 -w 20 -h 20
。
我的项目构建如下:
workspace
|__bg.txt
|__data/ # where I plan to put cascade
|__info/
|__ # all samples
|__info.lst
|__jersey5050.jpg
|__neg/
|__ # neg images
|__opencv/
|__positives.vec
在我运行opencv_createsamples -img jersey5050.jpg -bg bg.txt -info info/info.lst -maxxangle 0.5 - maxyangle 0.5 -maxzangle 0.5 -num 1800
不太清楚为什么我收到此错误。图像也都转换为灰度。 neg的大小为100x100,jersey5050.jpg
的大小为50x50。我看到有人在OpenCV论坛上有同样的错误,有人建议删除在OpenCV创建的备份.xml文件,以防培训被“中断”。我删除了那些,没有。请帮忙!我在mac上使用python 3。我也在带有2GB内存的digitalocean的ubuntu服务器上运行这些命令,但我不认为这是问题的一部分。
修改
忘记提及,在opencv_createsamples
命令后,我然后运行opencv_createsamples -info info/info.lst -num 1800 -w 20 -h20 -vec positives.vec
答案 0 :(得分:0)
我解决了哈哈。即使我在命令中指定宽度和高度为20x20,它也将其更改为20x24。所以opencv_traincascade
命令抛出错误。一旦我在opencv_traincascade
命令中更改了宽度和高度参数,它就会起作用。
答案 1 :(得分:0)
当传递的参数与生成的vec文件不匹配时会观察到此错误,这是终端在此行正确放置的
断言失败(_img.rows * _img.cols == vecSize)
opencv_createsamples显示传递给它进行训练的参数。请确认用于创建样本的参数与您传递的参数相同。我已附上终端日志以供参考。
mayank@mayank-Aspire-A515-51G:~/programs/opencv/CSS/homework/HAAR_classifier/dataset$ opencv_createsamples -info pos.txt -num 235 -w 40 -h 40 -vec positives_test.vec
Info file name: pos.txt
Img file name: (NULL)
Vec file name: positives_test.vec
BG file name: (NULL)
Num: 235
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: 40 <--- confirm
Height: 40 <--- confirm
Max Scale: -1
RNG Seed: 12345
Create training samples from images collection...
Done. Created 235 samples