OpenCV createsamples example -


i trying run createsamples example opencv library. can load in 1 image @ time , seems work fine. however, when try load in collection of images parse error. not sure if in collection file invalid or if missing elsewhere. below exact format of text document.

text document details:

target1.jpg 1 0 0 1296 1152 target2.jpg 1 0 0 1890 709 

command line call:

-info "c:\users\seb\desktop\learning samples\target\target.txt" -num 10 -vec "c:\users\seb\desktop\learning samples\target\target.vec" -maxxangle 0.6 -maxyangle 0 -maxzangle 0.3 -maxidev 100 -bgcolor 0 -bgthresh 0 -w 20 -h 20 

any appreciated.

the parse error because when not specify number of pos image samples want generate, createsamples use default value 1000. if annotation text document contains less 1000 bounding boxes of objects, parse error. can still use .vec file training cascade. problem information of number incorrect. there 2 ways fix it.

  1. you manually count number of object bounding boxes in text document. , specify value less or equal number option "-num" e.g. createsamples -info xxxxx.txt -vec pos.vec -num [value]

  2. you can revise opencv_root_dir/modules/haartraining/createsamples.cpp. when -num not specified, set number of pos samples number of object bounding boxes in text document

code snippet: in createsamples.cpp int num = 0;

in cvsamples.cpp

void icvwritevecheader( file* file, int count, int width, int height ) {     int vecsize;     short tmp;      fseek ( file , 0 , seek_set );      /* number of samples */     fwrite( &count, sizeof( count ), 1, file );     /* vector size */     vecsize = width * height;     fwrite( &vecsize, sizeof( vecsize ), 1, file );     /* min/max values */     tmp = 0;     fwrite( &tmp, sizeof( tmp ), 1, file );     fwrite( &tmp, sizeof( tmp ), 1, file );      fseek ( file , 0 , seek_end ); }  int cvcreatetrainingsamplesfrominfo( const char* infoname, const char* vecfilename,                                      int num,                                      int showsamples,                                      int winwidth, int winheight ) {     char fullname[path_max];     char* filename;      file* info;     file* vec;     iplimage* src=0;     iplimage* sample;     int line;     int error;     int i;     int x, y, width, height;     int total;      assert( infoname != null );     assert( vecfilename != null );      total = 0;     if( !icvmkdir( vecfilename ) )     {  #if cv_verbose         fprintf( stderr, "unable create directory hierarchy: %s\n", vecfilename ); #endif /* cv_verbose */          return total;     }      info = fopen( infoname, "r" );     if( info == null )     {  #if cv_verbose         fprintf( stderr, "unable open file: %s\n", infoname ); #endif /* cv_verbose */          return total;     }      vec = fopen( vecfilename, "wb" );     if( vec == null )     {  #if cv_verbose         fprintf( stderr, "unable open file: %s\n", vecfilename ); #endif /* cv_verbose */          fclose( info );          return total;     }      sample = cvcreateimage( cvsize( winwidth, winheight ), ipl_depth_8u, 1 );      icvwritevecheader( vec, num, sample->width, sample->height );      if( showsamples )     {         cvnamedwindow( "sample", cv_window_autosize );     }      strcpy( fullname, infoname );     filename = strrchr( fullname, '\\' );     if( filename == null )     {         filename = strrchr( fullname, '/' );     }     if( filename == null )     {         filename = fullname;     }     else     {         filename++;     }      while ( num<=0 || total<num )     {         int count;          error = ( fscanf( info, "%s %d", filename, &count ) != 2 );         if( !error )         {             src = cvloadimage( fullname, 0 );             error = ( src == null );             if( error )             {  #if cv_verbose                 fprintf( stderr, "unable open image: %s\n", fullname ); #endif /* cv_verbose */             }         }         else             if ( num <= 0 ) break;          for( = 0; < count; i++, total++ )         {             error = ( fscanf( info, "%d %d %d %d", &x, &y, &width, &height ) != 4 );             if( error ) break;             cvsetimageroi( src, cvrect( x, y, width, height ) );             cvresize( src, sample, width >= sample->width &&                       height >= sample->height ? cv_inter_area : cv_inter_linear );              if( showsamples )             {                 cvshowimage( "sample", sample );                 if( cvwaitkey( 0 ) == 27 )                 {                     showsamples = 0;                 }             }             icvwritevecsample( vec, sample );                          if ( num > 0 && total >= num ) break;         }          if ( num<=0 )             icvwritevecheader( vec, total, sample->width, sample->height );          if( src )         {             cvreleaseimage( &src );         }          if( error )         {  #if cv_verbose             fprintf( stderr, "%s(%d) : parse error", infoname, line ); #endif /* cv_verbose */              break;         }          }      if( sample )     {         cvreleaseimage( &sample );     }      fclose( vec );     fclose( info );      return total; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -