Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
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/[^]

C++
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;
}
Posted
Comments
barneyman 26-Oct-15 17:26pm    
argv[4] would be the *path* to the input file (ie /usr/binaryoffset/wibble.bmp), similarly argv[5] is the output *path*
barneyman 27-Oct-15 18:34pm    
arg0 is automatically supplied by the startup code - you don't need to specify it
binaryoffset 27-Oct-15 18:37pm    
Thank you. It's solved now and working. :)
Sergey Alexandrovich Kryukov 26-Oct-15 18:06pm    
It makes sense at all. There is nothing to "search" for. Programming is done by writing code, not "searching". You have all you need. Your argv is nothing but array of string. A string can be a file name, some option, anything. "To use or replace the "argv"" is nothing but absurd. You just read those strings and do with them whatever you want.
—SA
binaryoffset 27-Oct-15 15:37pm    
As much as I appreciate the information regarding an argv, there is no need for the criticism about "searching" for an example. I wouldn't have posted this if there wasn't a need, and I'm not the only one. Thanks again for your input.

1 solution

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

C++
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
C++
void theTest
{
  int n = 6;
  char args[][] = {"","","","","",""};//some useful values
  //run test
   myTestableFunction(n, args);
  //check results  ...
}
 
Share this answer
 
Comments
binaryoffset 27-Oct-15 18:33pm    
Thank you for this, very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900