示例#1
0
文件: flea_lib.c 项目: jaxiano/cuav
int capture(fleaCamera* camera, void* image_buf, float* frame_time)
{
    fc2Error error;
    fc2Image rawImage;
    fc2TimeStamp ts;

    error = fc2CreateImage( &rawImage );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateImage: %d\n", error );
    }

    // Retrieve the image
    error = fc2RetrieveBuffer( camera->context, &rawImage );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in retrieveBuffer: %d\n", error);
        return -1;
    }

    // Get and print out the time stamp
    ts = fc2GetImageTimeStamp( &rawImage);
    (*frame_time) = (ts.cycleSeconds * 8000) + ts.cycleCount;
/*
    diff = (ts.cycleSeconds - prevTimestamp.cycleSeconds) * 8000
                + (ts.cycleCount - prevTimestamp.cycleCount);
    prevTimestamp = ts;
    printf( 
        "timestamp [%d %d] - %d\n", 
        ts.cycleSeconds, 
        ts.cycleCount, 
        diff );
*/
    //PrintImageInfo(&rawImage);
    memcpy(image_buf, rawImage.pData, rawImage.dataSize);

    error = fc2DestroyImage( &rawImage );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2DestroyImage: %d\n", error );
    }
    return 0;
}
示例#2
0
void GrabImages( fc2Context context, int numImagesToGrab )
{
  fc2Error error;
  fc2Image rawImage;
  fc2Image convertedImage;
  fc2TimeStamp prevTimestamp = {0};
  int i;
  
  error = fc2CreateImage( &rawImage );
  if ( error != FC2_ERROR_OK )
  {
    printf( "Error in fc2CreateImage: %d\n", error );
  }
  
  error = fc2CreateImage( &convertedImage );
  if ( error != FC2_ERROR_OK )
  {
    printf( "Error in fc2CreateImage: %d\n", error );
  }
  
  // If externally allocated memory is to be used for the converted image,
  // simply assigning the pData member of the fc2Image structure is
  // insufficient. fc2SetImageData() should be called in order to populate
  // the fc2Image structure correctly. This can be done at this point,
  // assuming that the memory has already been allocated.
  
  for ( i=0; i < numImagesToGrab; i++ )
  {
    // Retrieve the image
    error = fc2RetrieveBuffer( context, &rawImage );
    if ( error != FC2_ERROR_OK )
    {
      printf( "Error in retrieveBuffer: %d\n", error);
    }
    else
    {
      // Get and print out the time stamp
      fc2TimeStamp ts = fc2GetImageTimeStamp( &rawImage);
      int diff = (ts.cycleSeconds - prevTimestamp.cycleSeconds) * 8000
	+ (ts.cycleCount - prevTimestamp.cycleCount);
      prevTimestamp = ts;
      printf( 
	     "timestamp [%d %d] - %d\n", 
	     ts.cycleSeconds, 
	     ts.cycleCount, 
	     diff );
    }       
  }
  
  if ( error == FC2_ERROR_OK )
  {
    // Convert the final image to RGB
    error = fc2ConvertImageTo(FC2_PIXEL_FORMAT_BGR, &rawImage, &convertedImage);
    if ( error != FC2_ERROR_OK )
    {
      printf( "Error in fc2ConvertImageTo: %d\n", error );
        }
    
    // Save it to PNG
    printf("Saving the last image to fc2TestImage.png \n");
    error = fc2SaveImage( &convertedImage, "fc2TestImage.png", FC2_PNG );
    if ( error != FC2_ERROR_OK )
    {
      printf( "Error in fc2SaveImage: %d\n", error );
      printf( "Please check write permissions.\n");
    }
  }
  
  error = fc2DestroyImage( &rawImage );
  if ( error != FC2_ERROR_OK )
  {
        printf( "Error in fc2DestroyImage: %d\n", error );
  }
  
  error = fc2DestroyImage( &convertedImage );
  if ( error != FC2_ERROR_OK )
  {
    printf( "Error in fc2DestroyImage: %d\n", error );
  }
}