Example #1
0
//! \brief Printing camera info
//!
//! \param FlyCapture2::Camera* pCamera
//!
//!
void PrintCameraInfo( FlyCapture2::Camera* pCamera )
{
    FlyCapture2::CameraInfo camInfo;
    FlyCapture2::Error error = pCamera->GetCameraInfo( &camInfo );
    PRINT_ERROR( error );
    PrintCameraInfo( camInfo );
}
Example #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;
}
Example #3
0
int main(int argc, char** argv)
{        
    fc2Error error;
    fc2Context context;
    fc2PGRGuid guid;
    unsigned int numCameras = 0;    
    const int k_numImages = 100;

    // Since this application saves images in the OUTPUT_DIR folder
    // we must ensure that the folder exists and we have permission 
    //to write to this folder. If we do not have permission, fail right away.
    struct stat sb;

    if (!(stat(OUTPUT_DIR, &sb) == 0 && S_ISDIR(sb.st_mode)))
    {
      printf("Directory %s NOT found\n",OUTPUT_DIR);
      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;
      }
    }
    // else
    // {
    //   printf("Directory %s NOT FOUND\n",OUTPUT_DIR);
    //}

    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



    PrintBuildInfo();

    error = fc2CreateContext( &context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateContext: %d\n", error );
        return 0;
    }        

    error = fc2GetNumOfCameras( context, &numCameras );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetNumOfCameras: %d\n", error );
        return 0;
    }

    if ( numCameras == 0 )
    {
        // No cameras detected
        printf( "No cameras detected.\n");
        return 0;
    }

    // Get the 0th camera
    error = fc2GetCameraFromIndex( context, 0, &guid );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetCameraFromIndex: %d\n", error );
        return 0;
    }    

    error = fc2Connect( context, &guid );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2Connect: %d\n", error );
        return 0;
    }

    PrintCameraInfo( context );    

    SetTimeStamping( context, TRUE );

    error = fc2StartCapture( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StartCapture: %d\n", error );
        return 0;
    }

    GrabImages( context, k_numImages );   

    error = fc2StopCapture( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StopCapture: %d\n", error );
        return 0;
    }

    error = fc2DestroyContext( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2DestroyContext: %d\n", error );
        return 0;
    }

    printf( "Done! Press Enter to exit...\n" );
    getchar();

	return 0;
}
Example #4
0
Camera::Camera(ros::NodeHandle _comm_nh, ros::NodeHandle _param_nh) :
      node(_comm_nh), pnode(_param_nh), it(_comm_nh),
      info_mgr(_comm_nh, "camera"), cam() {

      FlyCapture2::Error error;

      /* default config values */
      width = 640;
      height = 480;
      fps = 10;
      frame = "camera";
      rotate = false;

      /* set up information manager */
      std::string url;

      pnode.getParam("camera_info_url", url);

      info_mgr.loadCameraInfo(url);

      /* pull other configuration */
      pnode.getParam("serial", serial);

      pnode.getParam("fps", fps);
      pnode.getParam("skip_frames", skip_frames);

      pnode.getParam("width", width);
      pnode.getParam("height", height);

      pnode.getParam("frame_id", frame);

      /* advertise image streams and info streams */
      pub = it.advertise("image_raw", 1);

      info_pub = node.advertise<CameraInfo>("camera_info", 1);

      /* initialize the cameras */
      
      FlyCapture2::BusManager busMgr;
      
      FlyCapture2::PGRGuid guid;
      error = busMgr.GetCameraFromSerialNumber(serial, &guid);
      
      // Connect to a camera
      error = cam.Connect(&guid);
      if (error != FlyCapture2::PGRERROR_OK)
      {
          //PrintError( error );
          //return -1;
      }
      
      // Get the camera information
      FlyCapture2::CameraInfo camInfo;
      error = cam.GetCameraInfo(&camInfo);
      if (error != FlyCapture2::PGRERROR_OK)
      {
          //PrintError( error );
          //return -1;
      }

      PrintCameraInfo(&camInfo);

      FlyCapture2::GigEImageSettingsInfo imageSettingsInfo;
      error = cam.GetGigEImageSettingsInfo( &imageSettingsInfo );
      if (error != FlyCapture2::PGRERROR_OK)
      {
//          PrintError( error );
//P          return -1;
      }

      FlyCapture2::GigEImageSettings imageSettings;
      imageSettings.offsetX = 0;
      imageSettings.offsetY = 0;
      imageSettings.height = imageSettingsInfo.maxHeight;
      imageSettings.width = imageSettingsInfo.maxWidth;
      imageSettings.pixelFormat = FlyCapture2::PIXEL_FORMAT_RAW8;

      printf( "Setting GigE image settings...\n" );

      error = cam.SetGigEImageSettings( &imageSettings );
      if (error != FlyCapture2::PGRERROR_OK)
      {
//         PrintError( error );
//         return -1;
      }

      /* and turn on the streamer */
      error = cam.StartCapture();
      if (error != FlyCapture2::PGRERROR_OK)
      {
//          PrintError( error );
//          return -1;
      }
      ok = true;
      image_thread = boost::thread(boost::bind(&Camera::feedImages, this));
    }
Example #5
0
//! \brief Connect cameras and return camera objects
//!
//! \return unsigned int &numCameras
//! \return FlyCapture2::Camera** &ppCameras
//!
//!
void prepareCameras(unsigned int &numCameras,
                    FlyCapture2::Camera** &ppCameras)
{

    FlyCapture2::Error error;


    //!<
    //!< Get camera bus
    //!<

    FlyCapture2::BusManager busMgr;

    error = busMgr.GetNumOfCameras( &numCameras );
    PRINT_ERROR( error );
    std::cout << "Number of cameras detected: " << numCameras << std::endl;

    if ( numCameras < 1 )
    {
        std::cerr << "Insufficient number of cameras... press Enter to exit." << std::endl;
        getchar();
        exit(-1);
    }



    ppCameras = new FlyCapture2::Camera* [ numCameras ];


    //!<
    //!< Connect to all detected cameras and attempt to set them to a common video mode and frame rate
    //!<

    for ( unsigned int i = 0; i < numCameras; i++)
    {
        ppCameras[i] = new FlyCapture2::Camera();

        std::cout << "setting camera " << i << std::endl;

        FlyCapture2::PGRGuid guid;
        error = busMgr.GetCameraFromIndex( i, &guid );
        PRINT_ERROR( error );

        //!< Connect to a camera
        error = ppCameras[i]->Connect( &guid );
        PRINT_ERROR( error );


        PrintCameraInfo( ppCameras[i] );

        PrintCameraPropertyInfo( ppCameras[i] );



        //!< Set all cameras to a specific mode and frame rate so they can be synchronized
        error = ppCameras[i]->SetVideoModeAndFrameRate(FlyCapture2::VIDEOMODE_640x480Y8, //!< size of 640x480, format Mono8bit (Y8)
                                                       FlyCapture2::FRAMERATE_30 );
        PRINT_ERROR_MSG( error,
                        "Error starting cameras. \n"
                        "This example requires cameras to be able to set to 640x480 Y8 at 30fps. \n"
                        "If your camera does not support this mode, please edit the source code and recompile the application. \n"
                        "Press Enter to exit. \n");
    }


    std::cout << "all camera set to specific mode." << std::endl;


    error = FlyCapture2::Camera::StartSyncCapture( numCameras, (const FlyCapture2::Camera**)ppCameras );
    PRINT_ERROR_MSG( error,
                    "Error starting cameras. \n"
                    "This example requires cameras to be able to set to 640x480 Y8 at 30fps. \n"
                    "If your camera does not support this mode, please edit the source code and recompile the application. \n"
                    "Press Enter to exit. \n");

    std::cout << "StartSyncCapture." << std::endl;

}
int CameraPointGrey::init(bool isTrigger)
{
    PrintBuildInfo();

    error = busMgr.GetNumOfCameras(&numCameras);
    if (error != PGRERROR_OK) {
        PrintError(error);
        return -1;
    }
    printf("Number of cameras detected: %u\n", numCameras);
    if (numCameras /*< 1*/ != 2)
    {
        printf( "Insufficient number of cameras! Please check.\n" );
        return -1;
    }

    ppCameras = new FlyCapture2::Camera*[numCameras];
    // Connect to all detected cameras and attempt to set them to
    // a common video mode and frame rate
    for (unsigned int i = 0; i < numCameras; i++) {
        ppCameras[i] = new FlyCapture2::Camera();

        // PGRGuid guid
        PGRGuid guid;
        error = busMgr.GetCameraFromIndex(i, &guid);
        if (error != PGRERROR_OK) {
            PrintError(error);
            return -1;
        }

        //停止捕获和连接,以防之前的错误
        ppCameras[i]->StopCapture();
        ppCameras[i]->Disconnect();

        // Connect to a camera
        error = ppCameras[i]->Connect(&guid);
        if (error != PGRERROR_OK) {
            PrintError(error);
            return -1;
        }

        // Get the camera information
        CameraInfo camInfo;
        error = ppCameras[i]->GetCameraInfo(&camInfo);
        if (error != PGRERROR_OK) {
            PrintError(error);
            return -1;
        }
        PrintCameraInfo(&camInfo);

        {
            // Check for external trigger support
            TriggerModeInfo triggerModeInfo;
            error = ppCameras[i]->GetTriggerModeInfo(&triggerModeInfo);
            if (error != PGRERROR_OK) {
                PrintError(error);
                return -1;
            }
            if (triggerModeInfo.present != true) {
                printf( "Camera does not support external trigger!\n" );
                return -1;
            }
            // Get current trigger settings
            TriggerMode triggerMode;
            error = ppCameras[i]->GetTriggerMode(&triggerMode);
            if (error != PGRERROR_OK) {
                PrintError(error);
                return -1;
            }
            // Set camera to trigger mode 0
            triggerMode.onOff = isTrigger; // on or off
            triggerMode.mode = 0;
            triggerMode.parameter = 0;
            triggerMode.source = 0; // Triggering the camera externally using source 0, i.e., GPIO0.
            error = ppCameras[i]->SetTriggerMode(&triggerMode);
            if (error != PGRERROR_OK) {
                PrintError(error);
                return -1;
            }

            if (isTrigger) {
                // Poll to ensure camera is ready
                bool retVal = PollForTriggerReady(ppCameras[i]);
                if (!retVal) {
                    printf("\nError polling for trigger ready!\n");
                    return -1;
                }
            }
        }

        {
            Mode k_fmt7Mode = MODE_0;
            PixelFormat k_fmt7PixFmt = PIXEL_FORMAT_MONO8;

            // Query for available Format 7 modes
            Format7Info fmt7Info;
            bool supported;
            fmt7Info.mode = k_fmt7Mode;
            error = ppCameras[i]->GetFormat7Info(&fmt7Info, &supported);
            if (error != PGRERROR_OK) {
                PrintError(error);
                return -1;
            }
            PrintFormat7Capabilities( fmt7Info );

            if ((k_fmt7PixFmt & fmt7Info.pixelFormatBitField) == 0) {
                printf("Pixel format is not supported\n"); // Pixel format not supported!
                return -1;
            }

            Format7ImageSettings fmt7ImageSettings;
            fmt7ImageSettings.mode = k_fmt7Mode;
            fmt7ImageSettings.offsetX = 0;
            fmt7ImageSettings.offsetY = 0;
            fmt7ImageSettings.width = fmt7Info.maxWidth;
            fmt7ImageSettings.height = fmt7Info.maxHeight;
            fmt7ImageSettings.pixelFormat = k_fmt7PixFmt;

            bool valid;
            Format7PacketInfo fmt7PacketInfo;

            // Validate the settings to make sure that they are valid
            error = ppCameras[i]->ValidateFormat7Settings(
                        &fmt7ImageSettings,
                        &valid,
                        &fmt7PacketInfo);
            if (error != PGRERROR_OK) {
                PrintError(error);
                return -1;
            }
            if (!valid ) {
                printf("Format7 settings are not valid\n"); // Settings are not valid
                return -1;
            }

            // Set the settings to the camera
            error = ppCameras[i]->SetFormat7Configuration(
                        &fmt7ImageSettings,
                        //	fmt7PacketInfo.recommendedBytesPerPacket );
                        (unsigned int)516);
            if (error != PGRERROR_OK) {
                PrintError(error);
                return -1;
            }
        }


        VideoMode videoMode = VIDEOMODE_1024x768Y8;
        FrameRate frameRate = FRAMERATE_3_75;
        bool isSupported;
        ppCameras[i]->GetVideoModeAndFrameRateInfo(videoMode, frameRate, &isSupported);
        if (!isSupported) {
            printf("Video mode 1024x768 8bit, Frame rate 3.75, are not supported!\n");
            return -1;
        }
        ppCameras[i]->SetVideoModeAndFrameRate(videoMode, frameRate);



        // Camera is ready, start capturing images
        error = ppCameras[i]->StartCapture();
        if (error != PGRERROR_OK) {
            PrintError( error );
            return -1;
        }

        // Set all cameras to a specific mode and frame rate so they can be synchronized

        // Retrieve frame rate property
        Property frmRate;
        frmRate.type = FRAME_RATE;
        error = ppCameras[i]->GetProperty(&frmRate);
        if (error != PGRERROR_OK)
        {
            PrintError( error );
            return -1;
        }
        printf( "Framse rate is %3.2f fps\n", frmRate.absValue );


        /*************** property setting ***************/
        Property prop;
        //prop.type = BRIGHTNESS;
        //prop.type = AUTO_EXPOSURE;
        //prop.type = SHARPNESS;

        prop.type = GAMMA;
        ppCameras[i]->GetProperty(&prop);
        prop.absValue = 1.0f;
        ppCameras[i]->SetProperty(&prop, true);

        //prop.type = PAN;
        //prop.type = TILT;

        /*
        prop.type = SHUTTER;
        ppCameras[i]->GetProperty(&prop);
        prop.absValue = 28.0f;
        ppCameras[i]->SetProperty(&prop, true);
        */

        prop.type = GAIN;
        ppCameras[i]->GetProperty(&prop);
        prop.absValue = 0.0f;
        ppCameras[i]->SetProperty(&prop, true);

    }
    return 0;
}
Example #7
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; 
}
int main(int argc, char** argv)
{        
    fc2Error error;
    fc2Context context;
    fc2PGRGuid guid;
    unsigned int numCameras = 0;
    fc2CameraInfo camInfo[10];
    unsigned int numCamInfo = 10;
    FILE* tempFile;
    unsigned int i;

    PrintBuildInfo();

    // Since this application saves images in the current folder
    // we must ensure that we have permission to write to this folder.
    // If we do not have permission, fail right away.
    tempFile = fopen("test.txt", "w+");
    if (tempFile == NULL)
    {
        printf("Failed to create file in current folder.  Please check permissions.\n");
        return -1;
    }
    fclose(tempFile);
    remove("test.txt");    

    error = fc2CreateGigEContext( &context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateContext: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }        

    error = fc2DiscoverGigECameras( context, camInfo, &numCamInfo);
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2DiscoverGigECameras: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    printf( "Number of cameras discovered: %u\n", numCamInfo );

    for ( i=0; i < numCamInfo; i++)
    {
        PrintCameraInfo( &camInfo[i] );
    }

    error = fc2GetNumOfCameras( context, &numCameras );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetNumOfCameras: %s\n", fc2ErrorToDescription(error) );
        return 0;
    }

    if ( numCameras == 0 )
    {
        // No cameras detected
        printf( "No cameras detected.\n");
        return 0;
    }

    for (i=0; i < numCameras; i++)
    {
        fc2InterfaceType interfaceType;

        error = fc2GetCameraFromIndex( context, i, &guid);
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2GetCameraFromIndex: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }    

        error = fc2GetInterfaceTypeFromGuid( context, &guid, &interfaceType );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2GetInterfaceTypFromGuid: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }    

        if ( interfaceType == FC2_INTERFACE_GIGE )
        {
            RunSingleCamera( context, guid);
        }
    }

	error = fc2DestroyContext( context );
	if ( error != FC2_ERROR_OK )
	{
		printf( "Error in fc2DestroyContext: %d\n", error );
		return 0;
	}

    printf( "Done! Press Enter to exit...\n" );
    getchar();

	return 0;
}
int RunSingleCamera( fc2Context context, fc2PGRGuid guid)
{
    const int k_numImages = 1000;

    fc2Error error;
    fc2CameraInfo camInfo;
    unsigned int numStreamChannels = 0;
    fc2GigEImageSettingsInfo imageSettingsInfo;
    fc2Image rawImage, convertedImage;    
    fc2GigEImageSettings imageSettings;
    int imageCnt;
    unsigned int i;
    char filename[512];

    printf( "Connecting to camera...\n" );

    // Connect to a camera
    error = fc2Connect( context, &guid );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2Connect: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    // Get the camera information
    error = fc2GetCameraInfo( context, &camInfo);
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetCameraInfo: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    PrintCameraInfo(&camInfo);        

    error = fc2GetNumStreamChannels( context, &numStreamChannels );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetNumStreamChannels: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    for ( i = 0; i < numStreamChannels; i++)
    {
        fc2GigEStreamChannel streamChannel;
        error = fc2GetGigEStreamChannelInfo( context, i, &streamChannel );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2GetGigEStreamChannelInfo: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }

        printf( "\nPrinting stream channel information for channel %u:\n", i );
        PrintStreamChannelInfo( &streamChannel );
    }    

    printf( "Querying GigE image setting information...\n" );

    error = fc2GetGigEImageSettingsInfo( context, &imageSettingsInfo );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetGigEImageSettingsInfo: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    imageSettings.offsetX = 0;
    imageSettings.offsetY = 0;
    imageSettings.height = imageSettingsInfo.maxHeight;
    imageSettings.width = imageSettingsInfo.maxWidth;
    imageSettings.pixelFormat = FC2_PIXEL_FORMAT_MONO8;

    printf( "Setting GigE image settings...\n" );

    error = fc2SetGigEImageSettings( context, &imageSettings );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2SetGigEImageSettings: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    printf( "Starting image capture...\n" );

    // Start capturing images
    error = fc2StartCapture( context);
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StartCapture: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    // Prepare images
    error = fc2CreateImage( &rawImage );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateImage: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    error = fc2CreateImage( &convertedImage );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateImage: %s\n", fc2ErrorToDescription(error) );
        return -1;
    }

    for ( imageCnt=0; imageCnt < k_numImages; imageCnt++ )
    {              
        // Retrieve an image
        error = fc2RetrieveBuffer( context, &rawImage );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2RetrieveBuffer: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }

        printf( "Grabbed image %d\n", imageCnt );
        
        // Convert the raw image
        error = fc2ConvertImageTo( FC2_PIXEL_FORMAT_MONO8, 
                                &rawImage,
                                &convertedImage );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2ConvertImage: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }

        // Create a unique filename
        sprintf( filename, "GigEGrabEx-%u-%d.pgm", camInfo.serialNumber, imageCnt );

        /*
        // Save the image. If a file format is not passed in, then the file
        // extension is parsed to attempt to determine the file format.
        error = fc2SaveImage( &convertedImage, filename, FC2_PGM );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2SaveImage: %s\n", fc2ErrorToDescription(error) );
            return -1;
        }
        */
    }         

    printf( "Stopping capture...\n" );

    // Stop capturing images
    error = fc2StopCapture( context);
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StopCapture: %s\n", fc2ErrorToDescription(error) );
    }

    // Disconnect the camera
    error = fc2Disconnect( context);
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2Disconnect: %s\n", fc2ErrorToDescription(error) );
    }

    error = fc2DestroyImage( &rawImage );
    error = fc2DestroyImage( &convertedImage );

    return 0;
}