0

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;
}
  • I'm curious what you tried, and how it failed. – Rob Kennedy Oct 26 '15 at 21:28
  • if there are spaces in the file path you should use it with Quotation marks. like: `"path\to\file name.ext"` – SHR Oct 26 '15 at 22:20
  • Rob Kennedy, I tried replacing argv[4] with the image file path and argv[5] with the name of the output image. I also replaced sigma, k and min_size with values given in an example. But this didn't produce any output image file upon running the program. It never got the stage: printf("got %d components\n", num_ccs); printf("done! uff...thats hard work.\n"); – David Spears Oct 27 '15 at 19:57

1 Answers1

3

Just provide the name of the image file as an argument to the program.

a.out 1.0 1.0 100 Input Output

Input and Output are paths to an input image and output image respectively.

More info: What does int argc, char *argv[] mean?

Community
  • 1
  • 1
lcs
  • 4,227
  • 17
  • 36
  • I right-clicked on my project in Solution Explorer > Configuration Properties> Debugging. In Command Arguments I typed in: "C:\ Projects\segment\Debug>segment.exe" 0.5 500 20 "C:\ Projects\segment\segment\image.ppm" "C:\ Projects\segment\segment\output.ppm" trying to make sure I didn't leave any unnecessary spaces. However, argc = 7 when outputted though it should be 6. I would appreciate any guidance on how to resolve this problem, thanks. – David Spears Oct 27 '15 at 21:20
  • @DavidSpears Don't include the program as an argument – lcs Oct 27 '15 at 21:51