int main()

in lear_gist-1.2/compute_gist_stream.c [57:148]


int main(int argc,char **args) {

  const char *infilename="/dev/stdin";
  int nblocks=4;
  int n_scale=3;
  int n_orientation[50]={8,8,4};
  const char *outfilename="/dev/null";

  while(*++args) {
    const char *a=*args;

    if(!strcmp(a,"-h")) usage();
    else if(!strcmp(a,"-nblocks")) {
      if(!sscanf(*++args,"%d",&nblocks)) {
        fprintf(stderr,"could not parse %s argument",a);
        usage();
      }
    } else if(!strcmp(a,"-orientationsPerScale")) {
      char *c;
      n_scale=0;
      for(c=strtok(*++args,",");c;c=strtok(NULL,",")) {
        if(!sscanf(c,"%d",&n_orientation[n_scale++])) {
          fprintf(stderr,"could not parse %s argument",a);
          usage();
        }
      }
    } else if(!strcmp(a, "-o")) {
        outfilename = *++args;
        if(!outfilename) {
            fprintf(stderr,"no output file set\n");
            usage();
        }
    } else {
      infilename=a;
    }
  }

  FILE *f=fopen(infilename,"r");
  if(!f) {
    perror("could not open infile");
    exit(1);
  }

  FILE *out_f = fopen(outfilename, "w");
  if(!f) {
    perror("could not open outfile");
    exit(1);
  }

  int width = -1, height = -1;
  image_list_t *G = NULL;
  int tot_oris;

  int imno = 0;
  for(;;) {
      printf("image %d\n", imno);
      color_image_t *img = load_ppm(f);
      if (!img) break;
      if (width == -1) {
          width = img->width;
          height = img->height;
          printf("  width=%d height=%d\n", width, height);
          assert(width >= 8 && height >= 8);
          tot_oris=0;
          int i;
          for(i=0;i<n_scale;i++) tot_oris+=n_orientation[i];
          G = create_gabor(n_scale, n_orientation, width, height);
      } else {
          assert(width == img->width && height == img->height);
      }
      //   float *desc=color_gist_scaletab(im,nblocks,n_scale,norientation);

      color_prefilt(img, 4);

      float *g = color_gist_gabor(img, nblocks, G);

      int descsize = tot_oris*nblocks*nblocks*3;

      fwrite(&descsize, 1, sizeof(descsize), out_f);
      fwrite(g, descsize, sizeof(*g), out_f);
      free(g);

      color_image_delete(img);
      imno++;
  }
  fclose(out_f);
  fclose(f);
  image_list_delete(G);


  return 0;
}