首页 > 解决方案 > 尝试使用 opencv_createsamples 时出现 OpenCV 错误

问题描述

我正在尝试训练级联来检测人脸。我有 31 张带有面孔的图片,并且我使用opencv_annotation了工具来生成-info-file。该文件如下所示:

1 positiveImages/0.jpg 1 546 289 70 96
2 positiveImages/1.jpg 1 542 325 105 106
3 positiveImages/10.jpg 1 98 289 138 119
4 positiveImages/11.jpg 1 284 303 204 189
5 positiveImages/12.jpg 3 415 279 70 97 484 320 75 87 624 374 76 132
...

在此之后,我尝试使用该opencv_createsamples工具生成.vec用于训练级联的文件。这是我使用的命令:

opencv_createsamples -info file.txt -bg negatives.txt -vec cropped.vec -num 1920 -w 48 -h 48

这给了我以下带有错误的输出:

Info file name: file.txt
Img file name: (NULL)
Vec file name: cropped.vec
BG  file name: negatives.txt
Num: 1920
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: 48
Height: 48
Create training samples from images collection...
OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /home/travis/miniconda/conda-bld/conda_1486587069159/work/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp, line 3229
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/travis/miniconda/conda-bld/conda_1486587069159/work/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp:3229: error: (-215) ssize.area() > 0 in function resize

Aborted (core dumped)

据我了解,这个错误是想告诉我没有图像,对吗?我想知道为什么会这样。file.txt似乎没问题,它有正确的图像路径等。任何建议将不胜感激。

编辑。想知道是否有更好的方法来训练级联,例如用几千张人脸图片和几千张没有人脸的图片而不使用注释工具?如果正图像被裁剪成只包含人脸,我可以以某种方式只使用这两个文件夹进行训练吗?

编辑。我的文件夹结构是这样的:

/negativeImages
/positiveImages
file.txt
negatives.txt

我是opencv_createsamples从根开始的。

标签: pythonopencvannotationshaar-classifier

解决方案


推荐阅读