示例#1
0
void AssignName(fc2Context context, char *name) 
{
  fc2CameraInfo camInfo;
  check_point_grey(fc2GetCameraInfo(context, &camInfo));
  sprintf(name, "Camera_%d_", camInfo.serialNumber);
  //  printf("Identified: %s\n",name);
}
示例#2
0
int main(int argc, char** argv) {
    struct stat sb;
    if (!(stat(OUTPUT_DIR, &sb) == 0 && S_ISDIR(sb.st_mode)))
    {
        if (mkdir(OUTPUT_DIR, S_IRWXU | S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH) != 0)
        {
            printf("Error creating directory %s\n",OUTPUT_DIR);
            return -1;
        }
    }
    char tempFileName[512];
    sprintf(tempFileName, "%stest.txt",OUTPUT_DIR);
    FILE* tempFile = fopen(tempFileName, "w+");
    if (tempFile == NULL)
    {
        printf("Failed to create file in current folder.  Please check permissions.\n");
        return -1;
    }
    fclose(tempFile);
    remove(tempFileName);
    //if we get here, we know the directory exists and we can write to it
    //now set up, start, and grab image from camera
    fc2Context context;
    fc2PGRGuid guid;
    fc2Image raw_image, converted_image;
    Imlib_Image temp_image;
    check_point_grey(fc2CreateContext(&context));
    check_point_grey(fc2GetCameraFromIndex(context,0,&guid));
    check_point_grey(fc2Connect(context,&guid));
    check_point_grey(fc2SetDefaultColorProcessing(FC2_IPP));
    check_point_grey(fc2SetVideoModeAndFrameRate(context,
                     FC2_VIDEOMODE_1280x960Y8,
                     FC2_FRAMERATE_15));
    PrintCameraInfo(context);
    check_point_grey(fc2CreateImage(&raw_image));
    check_point_grey(fc2CreateImage(&converted_image));
    check_point_grey(fc2StartCapture(context));
    check_point_grey(fc2RetrieveBuffer(context,&raw_image));
    check_point_grey(fc2ConvertImageTo(FC2_PIXEL_FORMAT_BGRU,&raw_image,&converted_image));
    temp_image = imlib_create_image_using_copied_data(converted_image.cols,
                 converted_image.rows,
                 (unsigned int *)
                 converted_image.pData);
    imlib_context_set_image(temp_image);
    char filename[512];
    sprintf(filename,"%stest.ppm",OUTPUT_DIR);
    imlib_save_image(filename);
    printf("Saved %s\n",filename);
    //image saved, now clean up
    imlib_free_image_and_decache();
    check_point_grey(fc2StopCapture(context));
    check_point_grey(fc2DestroyContext(context));
    check_point_grey(fc2DestroyImage(&raw_image));
    check_point_grey(fc2DestroyImage(&converted_image));
    printf("finished cleanup\n");
    return 0;
}
示例#3
0
int main(int argc, char** argv){
  int numPics = 100;
  fc2VideoMode mode1 = FC2_VIDEOMODE_640x480Y8;
  char *mode1_str = "FC2_VIDEOMODE_640x480Y8";
  //fc2FrameRate rate1 = FC2_FRAMERATE_30;
  //char *rate1_str = "FC2_FRAMERATE_30";
  fc2VideoMode mode2 = FC2_VIDEOMODE_1280x960Y8;
  char *mode2_str = "FC2_VIDEOMODE_1280x960Y8"; 
  fc2FrameRate rate = FC2_FRAMERATE_15;
  char *rate_str = "FC2_FRAMERATE_15";
  fc2VideoMode mode;
  char *mode_str;
  //fc2FrameRate rate;
  //char *rate_str;

  //int prog_mode;
  int camOffset = 0;

  PrintBuildInfo();
  /* if (argc != 2)  */
  /* { */
  /*   printf("Error: Must chose mode\n"); */
  /*   printf("Usage: %s {1, 2, 3, 4, 5, 6} \n",argv[0]); */
  /*   printf("Modes: 1 = first camera at 1280x960Y8\n" */
  /* 	   "       2 = second camera at 1280x960Y8\n" */
  /* 	   "       3 = both cameras at 1280x960Y8\n" */
  /* 	   "       4 = first camera at 640x480Y8\n" */
  /* 	   "       5 = second camera at 640x480Y8\n" */
  /* 	   "       6 = both cameras at 640x480Y8\n"); */
  /*   return -1; */
  /* } */

  /* prog_mode = atoi(argv[1]);   */
  /* if ((prog_mode > 6) || (prog_mode < 1)) */
  /* { */
  /*   printf("Must chose valid mode, 1 through 6\n"); */
  /* } */
  if (CheckSaving(OUTPUT_DIR) != 0)
  {
    printf("Cannot save to %s, please check permissions\n",OUTPUT_DIR);
    return -1;
  }
  //have correct number of arguments and can save
  
  fc2Context tempContext;
  check_point_grey(fc2CreateContext(&tempContext));
  unsigned int numCams;
  check_point_grey(fc2GetNumOfCameras(tempContext, &numCams));
  check_point_grey(fc2DestroyContext(tempContext));
  if (numCams == 0)
  { //no cameras
    printf("No cameras found, exiting.\n");
    return -1;
  } 
  //if we get here, we know we have at least 1 camera connected

  /* if (prog_mode < 4) */
  /* { */
  /*   mode = FC2_VIDEOMODE_1280x960Y8; */
  /*   mode_str = "FC2_VIDEOMODE_1280x960Y8"; */
  /*   rate = FC2_FRAMERATE_15; */
  /*   rate_str = "FC2_FRAMERATE_15"; */
  /* } */
  //  printf("Using resolution %s and frame rate %s\n",mode_str,rate_str);

  /* if ((prog_mode == 1) || (prog_mode == 4)) */
  /* { // run only the first camera */
  /*   numCams = 1; */
  /* } */
  /* if ((prog_mode == 2) || (prog_mode == 5)) */
  /* { // run only the second camera */
  /*   camOffset = 1; */
  /* } */

  printf("Taking %i pictures per camera with %i camera(s).\n",numPics, (numCams - camOffset)); 
  

  struct point_grey *pg_ptr[numCams - camOffset];
  for (int i = 0; i < (numCams - camOffset); i++) //initialization loop
  {
    if (i == 0)
    {
      mode = mode2;
      mode_str = mode2_str;
      //rate = rate2;
      //rate_str = rate2_str;
    }
    else
    {
      mode = mode1;
      mode_str = mode1_str;
      //rate = rate1;
      //rate_str = rate1_str;
    }

    pg_ptr[i] =
      (struct point_grey *)point_grey_malloc(sizeof(struct point_grey));
    check_point_grey(fc2CreateContext(&pg_ptr[i]->context));
    check_point_grey(fc2GetCameraFromIndex(pg_ptr[i]->context,
					   (i + camOffset),
					   &pg_ptr[i]->guid));
    check_point_grey(fc2Connect(pg_ptr[i]->context,
				&pg_ptr[i]->guid));
    check_point_grey(fc2SetDefaultColorProcessing(FC2_NEAREST_NEIGHBOR_FAST));
    check_point_grey(fc2SetVideoModeAndFrameRate(pg_ptr[i]->context,
						 mode,
						 rate));
    AssignName(pg_ptr[i]->context, pg_ptr[i]->name);
    check_point_grey(fc2CreateImage(&pg_ptr[i]->raw_image));
    check_point_grey(fc2CreateImage(&pg_ptr[i]->converted_image));
    PrintCameraInfo(pg_ptr[i]->context);
    printf("Using resolution %s and frame rate %s\n",mode_str,rate_str);
    //**CALLING THIS HERE WILL WORK WITH 2 CAMERAS AT 640X480 BUT NOT AT
    //1280X960**
    check_point_grey(fc2StartCapture(pg_ptr[i]->context))
    printf("completed initialization loop iteration %d, %s\n",i,pg_ptr[i]->name);
  } // initialization loop

  Imlib_Image temp_image;
  double start = current_time();

  for (int j = 0; j < numPics; j++) //loop through numPics
  {
    for (int i = 0; i < (numCams - camOffset); i++) //picture taking loop
    {
      check_point_grey(fc2RetrieveBuffer(pg_ptr[i]->context,
					 &pg_ptr[i]->raw_image));
      check_point_grey(fc2ConvertImageTo(FC2_PIXEL_FORMAT_BGRU,
					 &pg_ptr[i]->raw_image,
					 &pg_ptr[i]->converted_image));
      temp_image = imlib_create_image_using_copied_data(pg_ptr[i]->converted_image.cols,
							pg_ptr[i]->converted_image.rows,
						  (unsigned int *)
						  pg_ptr[i]->converted_image.pData);


      printf("%simage_%d\n",pg_ptr[i]->name,j);
      if (j == (numPics - 1))
      {//save the final image from each camera
	SaveImlibImage(temp_image, pg_ptr[i]->name, mode_str);
      }
      else
      {
	imlib_context_set_image(temp_image);
	//this is where we would do something else with the image
	imlib_free_image_and_decache();
      }
    } //picture taking loop
  } //numPics loop

  double stop = current_time();
  //check elapsed time
  double elapsed = stop - start;
  double images_per_sec = (double)numPics / elapsed;
  printf("%d images per camera taken in %f seconds (%f images/sec/cam)\n",
	 numPics, elapsed, images_per_sec);

  for (int i = 0; i < (numCams - camOffset); i++) //cleanup loop
  {
    //**CALLING THIS HERE WILL WORK WITH 2 CAMERAS AT 640X480 BUT NOT AT
    //1280X960**
    check_point_grey(fc2StopCapture(pg_ptr[i]->context));

    check_point_grey(fc2DestroyContext(pg_ptr[i]->context));
    check_point_grey(fc2DestroyImage(&pg_ptr[i]->raw_image));
    check_point_grey(fc2DestroyImage(&pg_ptr[i]->converted_image));
    free(pg_ptr[i]);

    printf("completed cleanup loop iteration %d\n",i);
  } //cleanup loop  
  printf("Program complete!\n");
  return 0; 
}