OpenCV編程->Haar訓練(4)

前段時間跑Haartraining.exe的數據生成了如下的數據:


打開0文件夾:




裏面數據如上,在此:沒有生成xml文件。

解決方案:

方案一:

個人經驗,是負樣本有問題,解決方案(成功通過):
1。卡在某一層後,按ctrl+c結束
2。更新你的負樣本
3。不要刪除已經訓練出的cascade
4。繼續訓練,請注意是否要改動-nneg參數
P.S. 要haarconv.exe郵件至:amadeuzou at gmail.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, 0, 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章