Exemplo n.º 1
0
//
// idlpgr_GetCameraFromIndex
//
IDL_VPTR IDL_CDECL idlpgr_GetCameraFromIndex(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  int camera;
  fc2PGRGuid guid;
  IDL_VPTR idl_guid;
  IDL_ULONG *pd;
  IDL_MEMINT dim = 4;
  int i;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  camera = (argc == 2) ? (int) IDL_LongScalar(argv[1]) : 0;

  error = fc2GetCameraFromIndex(context, camera, &guid);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not acquire specified camera",
			 error);

  // transfer camera guid to IDL as a vector of ULONG values
  pd = (IDL_ULONG *) 
    IDL_MakeTempVector(IDL_TYP_ULONG, dim, IDL_ARR_INI_NOP, &idl_guid);
  for (i = 0; i < 4; i++)
    pd[i] = guid.value[i];
  
  return idl_guid;
}
Exemplo n.º 2
0
FC2_Camera_Identifier FC2_Camera__identifier_fetch(
  FC2_Camera camera, Unsigned index) {
    FC2_Camera_Identifier camera_identifier =
      Memory__new(FC2_Camera_Identifier);
    FC2_Error error = fc2GetCameraFromIndex(camera, index, camera_identifier);
    assert (error == FC2_ERROR_OK);
    return camera_identifier;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}
int main(int argc, char *argv[]) {

  const unsigned int cameraIndex = 0u;
  const unsigned int numImagesPerFPSMeasurement = 240u;
  const int windowWidth = 1440;
  const int windowHeight = 900;
  const char cascadeFilename[] = "haarcascade_frontalface_alt.xml";
  const double detectionScaleFactor = 1.25;
  const int detectionMinNeighbours = 4;
  const int detectionFlags = CV_HAAR_SCALE_IMAGE;
  const cv::Size detectionMinSize(120, 120);
  const cv::Size detectionMaxSize;
  const cv::Scalar detectionDrawColor(255.0, 0.0, 255.0);
  char strBuffer[256u];
  const size_t strBufferSize = 256u;

  int matType;
  cv::Mat equalizedGrayMat;

#ifdef _WIN32
  snprintf(strBuffer, strBufferSize, "%s/../%s", argv[0], cascadeFilename);
  cv::CascadeClassifier detector(strBuffer);
#else
  cv::CascadeClassifier detector(cascadeFilename);
#endif
  if (detector.empty()) {
    snprintf(strBuffer, strBufferSize, "%s could not be loaded.",
              cascadeFilename);
    SDL_ShowSimpleMessageBox(
      SDL_MESSAGEBOX_ERROR, "Failed to Load Cascade File", strBuffer, NULL);
    return EXIT_FAILURE;
  }
  std::vector<cv::Rect> detectionRects;

  fc2Error error;

  fc2Image image;
  error = fc2CreateImage(&image);
  if (error != FC2_ERROR_OK) {
    showFC2Error(error);
    return EXIT_FAILURE;
  }

  fc2Context context;
  error = fc2CreateContext(&context);
  if (error != FC2_ERROR_OK) {
    showFC2Error(error);
    return EXIT_FAILURE;
  }
  
  fc2PGRGuid cameraGUID;
  error = fc2GetCameraFromIndex(context, cameraIndex, &cameraGUID);
  if (error != FC2_ERROR_OK) {
    showFC2Error(error);
    return EXIT_FAILURE;
  }
  
  error = fc2Connect(context, &cameraGUID);
  if (error != FC2_ERROR_OK) {
    showFC2Error(error);
    return EXIT_FAILURE;
  }

  error = fc2StartCapture(context);
  if (error != FC2_ERROR_OK) {
    fc2Disconnect(context);
    showFC2Error(error);
    return EXIT_FAILURE;
  }

  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fc2StopCapture(context);
    fc2Disconnect(context);
    showSDLError();
    return EXIT_FAILURE;
  }

  SDL_Window *window = SDL_CreateWindow(
      "LookSpry", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
      windowWidth, windowHeight, 0u);
  if (window == NULL) {
    fc2StopCapture(context);
    fc2Disconnect(context);
    showSDLError();
    return EXIT_FAILURE;
  }

  SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0u);
  if (renderer == NULL) {
    fc2StopCapture(context);
    fc2Disconnect(context);
    SDL_DestroyWindow(window);
    showSDLError();
    return EXIT_FAILURE;
  }
  
  SDL_RendererInfo rendererInfo;
  SDL_GetRendererInfo(renderer, &rendererInfo);

  if (strcmp(rendererInfo.name, "direct3d") == 0) {
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
  } else if (strcmp(rendererInfo.name, "opengl") == 0) {
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
  }

  snprintf(strBuffer, strBufferSize, "LookSpry | %s", rendererInfo.name);
  SDL_SetWindowTitle(window, strBuffer);

  SDL_Texture *videoTex = NULL;
  void *videoTexPixels;
  int pitch;

  clock_t startTicks = clock();
  clock_t endTicks;
  unsigned int numImagesCaptured = 0u;

  bool running = true;
  bool detecting = true;
  bool mirroring = true;
  SDL_Event event;
  while (running) {
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_QUIT) {
        running = false;
        break;
      } else if (event.type == SDL_KEYUP) {
        switch(event.key.keysym.sym) {
        // When 'd' is pressed, start or stop [d]etection.
        case SDLK_d:
          detecting = !detecting;
          break;
        // When 'm' is pressed, [m]irror or un-mirror the video.
        case SDLK_m:
          mirroring = !mirroring;
          break;
        default:
          break;
        }
      }
    }

    error = fc2RetrieveBuffer(context, &image);
    if (error != FC2_ERROR_OK) {
       fc2Disconnect(context);
       SDL_DestroyTexture(videoTex);
       SDL_DestroyRenderer(renderer);
       SDL_DestroyWindow(window);
       showFC2Error(error);
       return EXIT_FAILURE;
    }

    if (videoTex == NULL) {
      equalizedGrayMat.create(image.rows, image.cols, CV_8UC1);
      SDL_RenderSetLogicalSize(renderer, image.cols, image.rows);
      Uint32 videoTexPixelFormat;
      switch (image.format) {
        // For monochrome capture modes, plan to render captured data to the Y
        // plane of a planar YUV texture.
        case FC2_PIXEL_FORMAT_RAW8:
        case FC2_PIXEL_FORMAT_MONO8:
          videoTexPixelFormat = SDL_PIXELFORMAT_YV12;
          matType = CV_8UC1;
          break;
        // For color capture modes, plan to render captured data to the entire
        // space of a texture in a matching color format.
        case FC2_PIXEL_FORMAT_422YUV8:
          videoTexPixelFormat = SDL_PIXELFORMAT_UYVY;
          matType = CV_8UC2;
          break;
        case FC2_PIXEL_FORMAT_RGB:
          videoTexPixelFormat = SDL_PIXELFORMAT_RGB24;
          matType = CV_8UC3;
          break;
        case FC2_PIXEL_FORMAT_BGR:
          videoTexPixelFormat = SDL_PIXELFORMAT_BGR24;
          matType = CV_8UC3;
          break;
        default:
          fc2StopCapture(context);
          fc2Disconnect(context);
          SDL_DestroyTexture(videoTex);
          SDL_DestroyRenderer(renderer);
          SDL_DestroyWindow(window);
          SDL_ShowSimpleMessageBox(
              SDL_MESSAGEBOX_ERROR, "Unsupported FlyCapture2 Pixel Format",
              "LookSpry supports RAW8, MONO8, 422YUV8, RGB, and BGR.", NULL);
          return EXIT_FAILURE;
      }
      videoTex = SDL_CreateTexture(
          renderer, videoTexPixelFormat, SDL_TEXTUREACCESS_STREAMING,
          image.cols, image.rows);
      if (videoTex == NULL) {
        fc2StopCapture(context);
        fc2Disconnect(context);
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        showSDLError();
        return EXIT_FAILURE;
      }
      snprintf(
          strBuffer, strBufferSize, "LookSpry | %s | %dx%d --> %dx%d",
          rendererInfo.name, image.cols, image.rows, windowWidth,
          windowHeight);
      SDL_SetWindowTitle(window, strBuffer);
    }

    cv::Mat srcMat(image.rows, image.cols, matType, image.pData, image.stride);
    if (detecting) {
      switch (image.format) {
        // For monochrome capture modes, just equalize.
        case FC2_PIXEL_FORMAT_RAW8:
        case FC2_PIXEL_FORMAT_MONO8:
          cv::equalizeHist(srcMat, equalizedGrayMat);
          break;
        // For color capture modes, convert to gray and equalize.
        case FC2_PIXEL_FORMAT_422YUV8:
          cv::cvtColor(srcMat, equalizedGrayMat, cv::COLOR_YUV2GRAY_UYVY);
          cv::equalizeHist(equalizedGrayMat, equalizedGrayMat);
          break;
        case FC2_PIXEL_FORMAT_RGB:
          cv::cvtColor(srcMat, equalizedGrayMat, cv::COLOR_RGB2GRAY);
          cv::equalizeHist(equalizedGrayMat, equalizedGrayMat);
          break;
        case FC2_PIXEL_FORMAT_BGR:
          cv::cvtColor(srcMat, equalizedGrayMat, cv::COLOR_BGR2GRAY);
          cv::equalizeHist(equalizedGrayMat, equalizedGrayMat);
          break;
        default:
          break;
      }
      // Run the detector on the equalized image.
      detector.detectMultiScale(
          equalizedGrayMat, detectionRects, detectionScaleFactor,
          detectionMinNeighbours, detectionFlags, detectionMinSize,
          detectionMaxSize);
      // Draw the resulting detection rectangles on the original image.
      for (cv::Rect detectionRect : detectionRects) {
        cv::rectangle(srcMat, detectionRect, detectionDrawColor);
      }
    }

    SDL_LockTexture(videoTex, NULL, &videoTexPixels, &pitch);

    switch (image.format) {
    case FC2_PIXEL_FORMAT_RAW8:
    case FC2_PIXEL_FORMAT_MONO8:
      // Make the planar YUV video gray by setting all bytes in its U and V
      // planes to 128 (the middle of the range).
      memset(((unsigned char *)videoTexPixels + image.dataSize), 128,
             image.dataSize / 2u);
      break;
    default:
      break;
    }

    if (mirroring) {
      // Flip the image data while copying it to the texture.
      cv::Mat dstMat(image.rows, image.cols, matType, videoTexPixels,
                     image.stride);
      cv::flip(srcMat, dstMat, 1);
    } else {
      // Copy the image data, as-is, to the texture.
      // Note that the PointGrey image and srcMat have pointers to the same
      // data, so the following code does reference the data that we modified
      // earlier via srcMat.
      memcpy(videoTexPixels, image.pData, image.dataSize);
    }

    SDL_UnlockTexture(videoTex);
    SDL_RenderCopy(renderer, videoTex, NULL, NULL);
    SDL_RenderPresent(renderer);

    numImagesCaptured++;
    if (numImagesCaptured >= numImagesPerFPSMeasurement) {
      endTicks = clock();
      snprintf(
          strBuffer, strBufferSize, "LookSpry | %s | %dx%d --> %dx%d | %ld FPS",
          rendererInfo.name, image.cols, image.rows, windowWidth,
          windowHeight,
          numImagesCaptured * CLOCKS_PER_SEC / (endTicks - startTicks));
      SDL_SetWindowTitle(window, strBuffer);
      startTicks = endTicks;
      numImagesCaptured = 0u;
    }
  }

  fc2StopCapture(context);
  fc2Disconnect(context);
  SDL_DestroyTexture(videoTex);
  SDL_DestroyRenderer(renderer);
  SDL_DestroyWindow(window);
  return EXIT_SUCCESS;
}
Exemplo n.º 6
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;
}
Exemplo n.º 8
0
fleaCamera* open_camera(int brightness, unsigned int height, unsigned int width)
{
        fc2Error error;
        fleaCamera* camera = calloc(1, sizeof(fleaCamera));
        fc2PGRGuid guid;
        fc2GigEImageSettings image_settings;
    
        printf("Creating context\n");
        error = fc2CreateGigEContext( &camera->context );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2CreateContext: %d\n", error );
            free(camera);
            return NULL;
        }        
    
        // Get the 0th camera
        fc2GetCameraFromIndex( camera->context, 0, &guid );
        
        error = fc2Connect( camera->context, &guid );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2Connect: %d\n", error );
            close_camera(camera);
            return NULL;
        }
    
        //set_property_value(camera, FC2_BRIGHTNESS, brightness);
        //PrintCameraInfo( camera->context );  
        //setup_camera( camera );
        SetTimeStamping( camera->context, TRUE );      
        error = fc2GetGigEImageSettings(camera->context, &image_settings);
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error getting image settings settings: %d\n", error );
            return NULL;
        }
    
       
        image_settings.width = width;
        image_settings.height = height;
        image_settings.offsetX = (int)(MAX_WIDTH - width)/2;
        image_settings.offsetY = (int)(MAX_HEIGHT - height)/2;
        image_settings.pixelFormat = FC2_PIXEL_FORMAT_RAW8;
    
        error = fc2SetGigEImageSettings(camera->context, &image_settings);
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error setting format7 settings: %d\n", error );
            return NULL;
        }
        sleep(0.5);
    
        error = fc2StartCapture( camera->context );
        if ( error != FC2_ERROR_OK )
        {
            printf( "Error in fc2StartCapture: %d\n", error );
        }
    
        sleep(0.5);

    return camera;
}