Esempio n. 1
0
void ofxffmv::initializeWithGUID(GUID cameraGuid,int cameraWidth,int cameraHeight,int cameraLeft,int cameraTop,bool useROI,unsigned char cameraDepth,int cameraFramerate,bool isPlaying)
{
	FlyCaptureInfoEx* tempArInfo = new FlyCaptureInfoEx[_MAX_CAMERAS_];
	unsigned int camNum = 0;
	flycaptureBusEnumerateCamerasEx( tempArInfo, &camNum );
	for (int i=0;i<camNum;i++)
	{
		if ((unsigned long)tempArInfo[i].SerialNumber == cameraGuid.Data1)
			index = i;
	}
	arInfo = tempArInfo[index];
	flycaptureCreateContext(&context);
	flycaptureInitialize( context, index );
	guid = cameraGuid;
	width = cameraWidth;
	height = cameraHeight;
	framerate = cameraFramerate;
	left = cameraLeft;
	top = cameraTop;
	roiMode = useROI;
	depth = cameraDepth;
	flycaptureStartCustomImage(context,0,left,top,width,height,100,FLYCAPTURE_MONO8);
	flycaptureGrabImage2( context, &fcImage );
	width = fcImage.iCols;
	height = fcImage.iRows;
	depth = (width*height!=0) ? fcImage.iRowInc/fcImage.iRows : 0;
	flycaptureSetColorProcessingMethod( context,FLYCAPTURE_DISABLE);
	isInitialized = true;
	delete tempArInfo;
}
Esempio n. 2
0
int ofxffmv::getCameraBaseCount()
{
   unsigned int tcamNum = 0;
   FlyCaptureInfoEx* tArInfo = new FlyCaptureInfoEx[_MAX_CAMERAS_];
   flycaptureBusEnumerateCamerasEx( tArInfo, &tcamNum );
   delete tArInfo;
   return tcamNum;
}
Esempio n. 3
0
void ofxffmv::listDevices()
{
    printf("The following are FFMV\n");
    // This function enumerates all the cameras found on the machine, across
    // all 1394 buses and cards. It fills an array of FlyCaptureInfoEx
    // structures with all of the pertinent information from the attached
    // cameras. The index of a given FlyCaptureInfoEx structure in the array
    // parInfo is the device number.
   flycaptureBusEnumerateCamerasEx( arInfo, &camNum );
	for( unsigned int uiBusIndex = 0; uiBusIndex < camNum; uiBusIndex++ )
   {
      FlyCaptureInfoEx* pinfo = &arInfo[ uiBusIndex ];
      printf(
		  "Index %u: %s, SerialNumber:  %u\n",
         uiBusIndex,
         pinfo->pszModelName,
         pinfo->SerialNumber );
   }
   printf("end of listing FFMV\n\n");
}
int 
main( int argc, char* argv[] )
{
   FlyCaptureError   error;
   FlyCaptureContext context;

   // check the arguments of the call to make sure the utility is being called properly.
   if (argc != 2){
      PrintUsage();

      printf( "Done!  (hit enter)" );
      getchar();

      return 0;
   } else {
      if (!((strcmp(argv[1], "-retrieve") == 0) || (strcmp(argv[1], "-capture") == 0)))
      {
	 PrintUsage();  

	 printf( "Done!  (hit enter)" );
	 getchar();

	 return 0;
      }
   }

   //
   // Enumerate the cameras on the bus.
   //
   FlyCaptureInfoEx  arInfo[ _MAX_CAMS ];
   unsigned int	     uiSize = _MAX_CAMS;

   error = flycaptureBusEnumerateCamerasEx( arInfo, &uiSize );
   _HANDLE_ERROR( error, "flycaptureBusEnumerateCameras()" );

   for( unsigned int uiBusIndex = 0; uiBusIndex < uiSize; uiBusIndex++ )
   {
      FlyCaptureInfoEx* pinfo = &arInfo[ uiBusIndex ];
      printf( 
         "Index %u: %s (%u)\n",
         uiBusIndex,
         pinfo->pszModelName,
         pinfo->SerialNumber );
   }

   //
   // Create the context.
   //
   error = flycaptureCreateContext( &context );
   _HANDLE_ERROR( error, "flycaptureCreateContext()" );
   
   //
   // Initialize the camera.
   //
   printf( "Initializing camera %u.\n", _CAMERA_INDEX );
   error = flycaptureInitialize( context, _CAMERA_INDEX );
   _HANDLE_ERROR( error, "flycaptureInitialize()" );

   //
   // Reset the camera to default factory settings by asserting bit 0
   //
   error = flycaptureSetCameraRegister( context, INITIALIZE, 0x80000000 );
   _HANDLE_ERROR( error, "flycaptureSetCameraRegister()" );

   //
   // Power-up the camera (for cameras that support this feature)
   //
   error = flycaptureSetCameraRegister( context, CAMERA_POWER, 0x80000000 );
   _HANDLE_ERROR( error, "flycaptureSetCameraRegister()" );

   //
   // Report camera info.
   //
   FlyCaptureInfoEx info;
   error = flycaptureGetCameraInfo( context, &info );
   _HANDLE_ERROR( error, "flycaptureGetCameraInfo()" );

   printf( "Camera info:\n" );
   reportCameraInfo( &info );

   //
   // Query and report on the camera's ability to handle custom image modes.
   // We use the maximum and unit values to determine the size of the image
   // which can be saved to flash.
   //
   bool		  bAvailable;
   unsigned int	  uiMaxImageSizeCols;
   unsigned int	  uiMaxImageSizeRows;
   unsigned int	  uiImageUnitSizeHorz;
   unsigned int	  uiImageUnitSizeVert;
   unsigned int   uiOffsetUnitSizeHorz;
   unsigned int   uiOffsetUnitSizeVert;
   unsigned int   uiPixelFormats;

   error = ::flycaptureQueryCustomImageEx(
      context,
      MODE,
      &bAvailable,
      &uiMaxImageSizeCols,
      &uiMaxImageSizeRows,
      &uiImageUnitSizeHorz,
      &uiImageUnitSizeVert,
      &uiOffsetUnitSizeHorz,
      &uiOffsetUnitSizeVert,
      &uiPixelFormats );
   _HANDLE_ERROR( error, "flycaptureQueryCustomImageEx()" );

   //
   // Check to see if Flash Reading/Writing is supported by the camera
   //
   unsigned long ulRegVal;
   error = flycaptureGetCameraRegister(context, DATA_FLASH_CTRL, &ulRegVal);
   printf( "Data control register = %x\n", ulRegVal );

   if((0x80000000 & ulRegVal) == 0)
   {
      printf("This camera does not support the user data area feature. Exiting...\n");
     
      //
      // Destroy the context
      //
      flycaptureDestroyContext(context);

      printf( "Done!  (hit enter)" );
      getchar();

      return 0;
   }

   // Determine the available size of the Flash from the DATA_FLASH_CTRL register
   int iPageSize = (int)pow(2.0, (int)(ulRegVal & 0x00FFF000) >> 12);
   int iNumPages = (int)pow(2.0, (int)(ulRegVal & 0x00000FFF));
   unsigned int uiAvailableFlashSize = iPageSize * iNumPages;

   unsigned int uiHeight = uiMaxImageSizeCols;
   unsigned int uiWidth = uiMaxImageSizeRows;

   // If the Flash is not large enough to hold a full, high-res image, determine the
   // maximum image with a 4:3 aspect ration which can fit in the flash and use those
   // dimensions.
   if (uiMaxImageSizeCols*uiMaxImageSizeRows > uiAvailableFlashSize)
   {
      uiHeight = (int)sqrt(uiAvailableFlashSize*3.0/4);
      uiWidth = uiHeight*4/3;

      uiHeight -= (uiHeight % uiImageUnitSizeVert);
      uiWidth -= (uiWidth % uiImageUnitSizeHorz);
   }

   //
   // Determine the quadlet offset of the Flash area
   //
   unsigned long ulLUTLoc;
   error = flycaptureGetCameraRegister(context, DATA_FLASH_DATA, &ulLUTLoc);
   _HANDLE_ERROR( error, "flycaptureGetCameraRegister()" );   

   //
   // Start grabbing images in the current videomode and framerate.
   //
   printf( "Starting camera.\n\n" );
   error = flycaptureStartCustomImage(context, 0, 0, 0, uiWidth, uiHeight, 40, FLYCAPTURE_MONO8);
   _HANDLE_ERROR( error, "flycaptureStart()" );

   FlyCaptureImage image;
   memset( &image, 0x0, sizeof( FlyCaptureImage ) );

   // Here, we grab 10 images and only look at the last one, since after starting the camera,
   // it takes a few images for the the auto settings to stabilize (ie. exposure, gain, etc)
   for ( int iImage = 0; iImage < _IMAGES_TO_GRAB; iImage++ )
   {
      error = flycaptureGrabImage2( context, &image );
      _HANDLE_ERROR( error, "flycaptureGrabImage2()" );
   }

   // Check to see if we are capturing or retrieving
   if (strcmp(argv[1], "-capture") == 0)
   {

      printf( "Saving raw image to camera FLASH.\n\n" );

      //
      // Write the image to the cameras flash
      //
      error =  flycaptureWriteRegisterBlock(
	 context,
	 0xFFFF,
	 0xF0000000+ulLUTLoc*4,
	 (const unsigned long*)&(image.pData[0]),
	 (image.iRowInc*image.iRows/4));
      _HANDLE_ERROR( error, "flycaptureWriteRegisterBlock()" );

   } else if (strcmp(argv[1], "-retrieve") == 0){ // if we are not capturing (we are retrieving).

      printf( "Grabbing image from FLASH and saving it to disk as %s.\n\n", FILENAME_RAW_FROM_FLASH );

      // Create a flycapture image to save
      FlyCaptureImage savedImage;
      memset( &savedImage, 0x0, sizeof( FlyCaptureImage ) );

      // Fill in the savedImage structure
      savedImage.iCols = image.iCols;
      savedImage.iRows = image.iRows;
      savedImage.iRowInc = image.iRowInc;
      savedImage.videoMode = image.videoMode;
      savedImage.timeStamp = image.timeStamp;
      savedImage.bStippled = image.bStippled;
      savedImage.pixelFormat = image.pixelFormat;
      savedImage.iNumImages = image.iNumImages;
      savedImage.pData = (unsigned char*)malloc(savedImage.iRowInc*savedImage.iRows);

      // Read data from the flash into the SavedImage structure
      error = flycaptureReadRegisterBlock(
	 context,
	 0xFFFF,
	 0xF0000000+ulLUTLoc*4,
	 (unsigned long*)&(savedImage.pData[0]),
	 (savedImage.iRowInc*savedImage.iRows/4));
      _HANDLE_ERROR( error, "flycaptureReadRegisterBlock()" );   

      // Save the image to disk
      error = flycaptureSaveImage(
	 context,
	 &savedImage,
	 FILENAME_RAW_FROM_FLASH,
	 FLYCAPTURE_FILEFORMAT_PGM );
      _HANDLE_ERROR( error, "flycaptureSaveImage()" );

      free(savedImage.pData);

   } else {

      // We should never get here since the check at the top should catch this,
      // but this is here for completeness.
      PrintUsage();

   }

   //
   // Stop the camera
   //
   error = flycaptureStop( context );
   _HANDLE_ERROR( error, "flycaptureStop()" );

   //
   // Destroy the context.
   //
   error = flycaptureDestroyContext( context );
   _HANDLE_ERROR( error, "flycaptureDestroyContext()" );

   printf( "Done!  (hit enter)" );
   getchar();

   return 0;
}