OpenCV学习——物体跟踪的粒子滤波算法实现之命令行参数处理

void arg_parse( int argc, char** argv )
{
int i = 0;
/*extract program name from command line (remove path, if present) */
pname = remove_path( argv[0] );

/*parse commandline options */
while( TRUE )
{
char* arg_check;
int arg = getopt( argc, argv, OPTIONS );
if( arg == -1 )
break;

switch( arg )
{
/* user asked for help */
case 'h':
usage( pname );
exit(0);
break;

case 'a':
show_all = TRUE;
break;

/* user wants to output tracking sequence */
case 'o':
export = TRUE;
break;

/* user wants to set number of particles */
case 'p':
if( ! optarg )
fatal_error( "error parsing arguments at -%c\n" \
"Try '%s -h' for help.", arg, pname );
num_particles = strtol( optarg, &arg_check, 10 );
if( arg_check == optarg || *arg_check != '\0' )
fatal_error( "-%c option requires an integer argument\n" \
"Try '%s -h' for help.", arg, pname );
break;

/* catch invalid arguments */
default:
fatal_error( "-%c: invalid option\nTry '%s -h' for help.",
optopt, pname );
}
}

/* make sure input and output files are specified */
if( argc - optind < 1 )
fatal_error( "no input image specified.\nTry '%s -h' for help.", pname );
if( argc - optind > 2 )
fatal_error( "too many arguments.\nTry '%s -h' for help.", pname );

/* record video file name */
vid_file = argv[optind];
}

作者使用Getopt这个系统函数对命令行进行解析,-h表示显示帮助,-a表示将所有粒子所代表的位置都显示出来,-o表示输出tracking的帧,-p number进行粒子数的设定,然后再最后指定要处理的视频文件。

你可能感兴趣的:(C++,c,算法,C#)