OpenCV编程->Haar训练(4)

前端之家收集整理的这篇文章主要介绍了OpenCV编程->Haar训练(4)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前段时间跑Haartraining.exe的数据生成了如下的数据:


打开0文件夹:




里面数据如上,在此:没有生成xml文件

解决方案:

方案一:

个人经验,是负样本有问题,解决方案(成功通过):
1。卡在某一层后,按ctrl+c结束
2。更新你的负样本
3。不要删除已经训练出的cascade
4。继续训练,请注意是否要改动-nneg参数
P.S.要haarconv.exe邮件至:amadeuzouatgmail.com

来自:http://bbs.csdn.net/topics/340228399

方案二:

OpenCV的yahoo论坛上可以找到一个haarconv的程序,才将分类器转换为xml文件

在opencv2.4.8的文件夹里面找到了haarconv的源码如下(在目录OpenCV/samples/c/convert_cascade.c):

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <ctype.h>
#include <stdio.h>

static void help(void)
{
    printf("\n This sample demonstrates cascade's convertation \n"
    "Usage:\n"
    "./convert_cascade --size=\"<width>x<height>\"<convertation size> \n"
    "                   input_cascade_path \n"
    "                   output_cascade_filename\n"
    "Example: \n"
    "./convert_cascade --size=640x480 ../../opencv/data/haarcascades/haarcascade_eye.xml ../../opencv/data/haarcascades/test_cascade.xml \n"
    );
}

int main( int argc,char** argv )
{
    const char* size_opt = "--size=";
    char comment[1024];
    CvHaarClassifierCascade* cascade = 0;
    CvSize size;

    help();

    if( argc != 4 || strncmp( argv[1],size_opt,strlen(size_opt) ) != 0 )
    {
        help();
        return -1;
    }

    sscanf( argv[1],"--size=%ux%u",&size.width,&size.height );
    cascade = cvLoadHaarClassifierCascade( argv[2],size );

    if( !cascade )
    {
        fprintf( stderr,"Input cascade could not be found/opened\n" );
        return -1;
    }

    sprintf( comment,"Automatically converted from %s,window size = %dx%d",argv[2],size.width,size.height );
    cvSave( argv[3],cascade,comment,cvAttrList(0,0) );
    return 0;
}

#ifdef _EiC
main(1,"facedetect.c");
#endif

输入的格式为:

$ convert_cascade --size="<sample_width>x<sampe_height>" <haartraining_ouput_dir> <ouput_file>


举例:

$ convert_cascade --size="20x20" haarcascade haarcascade.xml

猜你在找的XML相关文章