使用“argv”传递图像文件C ++ [英] Using "argv" to pass image files C++

查看:112
本文介绍了使用“argv”传递图像文件C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我目前正在测试图像分割程序,需要以某种方式在主程序中传递测试图像文件,如下所示。一直在寻找。我将非常感谢如何使用或替换argv与测试图像文件,从而生成输出文件。非常感谢您的指导!



http://cs.brown .edu / ~pff / segment / [ ^ ]



  int  main( int  argc, char  ** argv){
if ( argc!= 6 ){
fprintf(stderr, 用法:%s sigma k min输入(ppm)输出(ppm)\ n,argv [ 0 ]);
return 1 ;
}

float sigma = atof(argv [ 1 ] );
float k = atof(argv [ 2 ]);
int min_size = atoi(argv [ 3 ]);

printf( loading input image.\ n);
image< rgb> * input = loadPPM(argv [ 4 ]);

printf( processing\\\
);
int num_ccs;
image< rgb> * seg = segment_image(input,sigma,k,min_size,& num_ccs);
savePPM(seg,argv [ 5 ]);

printf( 得到%d components \ n,num_ccs) ;
printf( done!uff ... thats hard work.\) ;

return 0 ;
}

解决方案

你必须用一个函数替换你的内部主代码,所以它看起来像这样:



  int  main( int  argc, char  ** argv){
myTestableFunction(argc,argv);

return 0 ;
}





以及您可以在测试代码中使用的myTestableFunction函数。它应该像这样工作

  void  theTest 
{
int n = 6 ;
char args [] [] = { }; // 一些有用的值
// run test
myTestableFunction(n,args);
// 检查结果...
}


Hello to you all. I am currently testing a program of image segmentation and need to somehow pass a test image file in the main program as shown below. Been searching for a while. I would appreciate an example of how to use or replace the "argv" with the test image file and consequently produce an output file. Much appreciate your guidance!

http://cs.brown.edu/~pff/segment/[^]

int main(int argc, char **argv) {
  if (argc != 6) {
    fprintf(stderr, "usage: %s sigma k min input(ppm) output(ppm)\n", argv[0]);
    return 1;
  }
  
  float sigma = atof(argv[1]);
  float k = atof(argv[2]);
  int min_size = atoi(argv[3]);
	
  printf("loading input image.\n");
  image<rgb> *input = loadPPM(argv[4]);
	
  printf("processing\n");
  int num_ccs; 
  image<rgb> *seg = segment_image(input, sigma, k, min_size, &num_ccs); 
  savePPM(seg, argv[5]);

  printf("got %d components\n", num_ccs);
  printf("done! uff...thats hard work.\n");

  return 0;
}

解决方案

you must replace your inner main code with a function, so it looks like this:

int main(int argc, char **argv) {
  myTestableFunction( argc, argv);

return 0;
}



and the myTestableFunction function you can use in your testcode. It should work like this

void theTest
{
  int n = 6;
  char args[][] = {"","","","","",""};//some useful values
  //run test
   myTestableFunction(n, args);
  //check results  ...
}


这篇关于使用“argv”传递图像文件C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆