opencv Haartraining

本文详细介绍了如何使用OpenCV的haar training程序来训练分类器,特别是在人脸识别方面的应用。作者在编译opencv_haartraining过程中遇到了问题,经过调整参数解决了assertion failed的错误。通过调整-npos和-nneg参数,遵循公式vec-file has to contain >= (numPos + (numStages-1) * (1 - minHitRate) * numPos) + S,重新训练成功。
摘要由CSDN通过智能技术生成

如何利用OpenCV自带的haar training程序训练分类器 - 计算机视觉小菜鸟的专栏 - 博客频道 - CSDN.NET  http://blog.csdn.net/carson2005/article/details/8171571

基于opencv的haar算法以人脸识别为例的训练分类器xml的方法 - - 博客频道 - CSDN.NET  http://blog.csdn.net/tender8888/article/details/7278091

opencv haar+adaboost使用心得 . - liulina603的专栏 - 博客频道 - CSDN.NET  http://blog.csdn.net/liulina603/article/details/8197889

参考了以上几篇博客

1、自己编译了opencv application下的opencv_haartraining,勾选了OpenMp选项vs--->project-->properties-->c++-->language-->OpenMp support 

2、提取的正样本样本总共6729,负样本315张图片,参考使用心得这篇文章,输入opencv_haartraining.exe -data xml -vec pos.vec -bg neg\neg.txt -w 20 -h 20 -mem 1024 -npos 6729 -nneg 6729 -nstages 22 出错。OpenCV Error: Assertion failed (elements_read == 1) in unknown function, file ..\..\..\..\opencv\apps\haartraining\cvhaartraining.cpp, line 1859  

别人也遇到这个问题,c++ - haar training OpenCV assertion failed - Stack Overflow  http://stackoverflow.com/questions/10863560/haar-training-opencv-assertion-failed

The problem is that your vec-file has exactly the same samples count that you passed in command line -numPos 979. Training application used all samples from the vec-file to train 0-stage and it can not get new positive samples for the next stage training because vec-file is over. The bug of traincascade is that it had assert() in such cases, but it has to throw an exception with error message for a user. It was fixed in r8913. -numPose is a samples count that is used to train each stage. Some already used samples can be filtered by each previous stage (ie recognized as background), but no more than (1 - minHitRate) * numPose on each stage. So vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file that can be recognized as background right away. I hope it can help you to create vec-file of correct size and chose right numPos value.

所以我的npos 跟 nneg过大,应参考上面这个公式。vec-file has to contain >= (numPos + (numStages-1) * (1 - minHitRate) * numPos) + S


重新训练:opencv_haartraining.exe -data xml -vec pos.vec -bg neg\neg.txt -w 20 -h 20 -mem 1024 -npos 3000 -nneg 315 -nstages 22


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值