Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:56:54+00:00 2026-05-29T09:56:54+00:00

I am trying to run the createsamples example from the OpenCV library. I can

  • 0

I am trying to run the createsamples example from the OpenCV library. I can load in one image at a time and it seems to work fine. However, when I try to load in a collection of images I get a parse error. I am not sure if it is something in my collection file that is invalid or if I am missing something elsewhere. Below is the exact format of my 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 help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:56:55+00:00Added an answer on May 29, 2026 at 9:56 am

    The parse error is because when you do not specify the number of pos image samples you want to generate, the createsamples will use the default value which is 1000. But if your annotation text document contains less than 1000 bounding boxes of objects, you will get the parse error. You can still use the .vec file for training cascade. The only problem is that the information of number is incorrect. There are two ways to fix it.

    1. You manually count the number of object bounding boxes in the text document. And specify the value less or equal to the number for the option “-num”
      e.g. createsamples -info xxxxx.txt -vec pos.vec -num [value]

    2. You can revise the OPENCV_ROOT_DIR/modules/haartraining/createsamples.cpp. When the -num is not specified, set the number of pos samples as the number of object bounding boxes in the 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 to create directory hierarchy: %s\n", vecfilename );
    #endif /* CV_VERBOSE */
    
            return total;
        }
    
        info = fopen( infoname, "r" );
        if( info == NULL )
        {
    
    #if CV_VERBOSE
            fprintf( stderr, "Unable to open file: %s\n", infoname );
    #endif /* CV_VERBOSE */
    
            return total;
        }
    
        vec = fopen( vecfilename, "wb" );
        if( vec == NULL )
        {
    
    #if CV_VERBOSE
            fprintf( stderr, "Unable to 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 to open image: %s\n", fullname );
    #endif /* CV_VERBOSE */
                }
            }
            else
                if ( num <= 0 ) break;
    
            for( i = 0; i < 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;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I
I am trying run a program from a qmake .pro file which modifies the
I'm trying to run a batch file, as another user, from my web app.
When trying to run my application on the emulator I get an error from
Trying to run a simple svn list svn+ssh://... from within jenkins on os X,
When trying to run android application from eclipse console shows [2012-01-31 14:01:01 - Remix_6Dec11]
Trying to run some sql in a pl/sql procedure. Select field from schema.view; I
trying to run this basic form control example on msdn. At step 1 of
Trying to run a script on the page load, where if a className is
I´m trying to run an old .NET application from an ASP.NET website. After reading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.