예제 #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;
}
//======================================================================================
// implimetation of functions for IEEE1394 camera (for Point Gray Inc.)
//======================================================================================
// initialize camera
bool IEEE1394Cam::Opens() {
#ifdef WIN32
	FlyCaptureError fe;

	// Open the camera
	fe = flycaptureCreateContext( &_flycapture );
	if (fe != FLYCAPTURE_OK) {
		return false;
	}

	// Initialize the WebIEEE1394Cam context
	fe = flycaptureInitialize( _flycapture, 0 );
	if (fe != FLYCAPTURE_OK) {
		return false;
	}

	// Get camera information
	fe = flycaptureGetCameraInfo( _flycapture, &_pInfo );
	if (fe != FLYCAPTURE_OK) {
		return false;
	}

	// set video mode
	_videoMode = FLYCAPTURE_VIDEOMODE_ANY;

	if ( _pInfo.CameraModel == FLYCAPTURE_BUMBLEBEE2 || _pInfo.CameraModel == FLYCAPTURE_FLEA2 || _pInfo.CameraModel == FLYCAPTURE_FLEA ) {
		// start transfering the image from camera
		if (!_use_stereo) {
			// flea, flea2
			fe = flycaptureStart( _flycapture, _videoMode, FLYCAPTURE_FRAMERATE_ANY);
		} else {
			// bumblebee2
			fe = flycaptureStartCustomImage( _flycapture, 3, 0, 0, 640, 480, 100, FLYCAPTURE_RAW16);
		}
		
		if (fe != FLYCAPTURE_OK) {
			return false;
		}
	} else {
		// camera is not supported by this class
		return false;
	}

	FlyCaptureImage flycaptureImage;
	// Grab an image from the camera
	fe = flycaptureGrabImage2( _flycapture, &flycaptureImage );
	if (fe != FLYCAPTURE_OK) {
		return false;
	}
	
	_height = flycaptureImage.iRows;
	_width = flycaptureImage.iCols;
	_row_size =	flycaptureImage.iRowInc;

	_activated = true;
	return true;
#else
	return false;
#endif //WIN32
}
int
main( int /* argc */, char** /* argv */ )
{
   FlyCaptureContext flycapture;
   FlyCaptureInfoEx cameraInfo;   
   FlyCaptureError   fe;
   
   // Create the Flycapture context
   fe = flycaptureCreateContext( &flycapture );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureCreateContext()", fe );
   
   // Initialize the camera
   fe = flycaptureInitialize( flycapture, 0 );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureInitialize()", fe );

   // Get the camera info  
   fe = flycaptureGetCameraInfo( flycapture, &cameraInfo );
   _HANDLE_FLYCAPTURE_ERROR( "flycatpureGetCameraInfo()", fe );

   // A string to hold the calibration file name
   // We will construct a meaningful name for the written calibration file
//   char* szFilename = new char[512];
//   sprintf( szFilename, "bumblebee%7.7u.cal", cameraInfo.SerialNumber );

   // Currently, we can not pass in our own filename to save to when saving
   // the calibration file.  The flycaptureGetCalibrationFileFromCamera function
   // will return the location of the saved file instead.  This will be fixed
   // shortly.
   char* szFilename = NULL;   

   // Get the camera configuration
   fe = flycaptureGetCalibrationFileFromCamera( flycapture, &szFilename );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureGetCalibrationFileFromCamera()", fe );

   printf("Calibration File successfully saved at %s", szFilename);
   
   // Destroy the Flycapture context
   flycaptureDestroyContext( flycapture );  

   if ( szFilename != NULL )
   {
      delete [] szFilename;
   }
   
   return 0;
}
예제 #4
0
void configureExternalTriggerCamera(FlyCaptureContext  context){
	FlyCaptureError    error;
   FlyCaptureImage      image;

   //printf( "Initializing camera.\n" );

      
   //
   // Initialize the first camera on the bus.
   //
   error = flycaptureInitialize( context, 0 );
   _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()" );

   //
   // Determine whether or not the camera supports external trigger mode.
   // If it does, put the camera into external trigger mode and otherwise 
   // exit.
   //
   bool bTriggerPresent;

   error = flycaptureQueryTrigger( 
      context, &bTriggerPresent, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
   _HANDLE_ERROR(error, "flycaptureQueryTrigger()" );

   if( !bTriggerPresent)
   {
      printf("This camera does not support external trigger... exiting\n");
   }

   int   iPolarity;
   int   iSource;
   int   iRawValue;
   int   iMode;

   error = flycaptureGetTrigger( 
      context, NULL, &iPolarity, &iSource, &iRawValue, &iMode, NULL );
   _HANDLE_ERROR(error, "flycaptureGetTrigger()" );

   //printf( "Going into asynchronous Trigger_Mode_0.\n" );
   //
   // Ensure the camera is in Trigger Mode 0 by explicitly setting it, 
   // as the camera could have a different default trigger mode
   //
#ifdef SOFTWARE_TRIGGER_CAMERA
   //
   // We are triggering the camera using the internal software trigger.
   // If we are using the DCAM SOFTWARE_TRIGGER functionality, we must
   // change the Trigger_Source to reflect the Software Trigger ID = 7.
   //
   error = flycaptureSetTrigger( 
      context, true, iPolarity, 7, 0, 0 );
   _HANDLE_ERROR( "flycaptureSetCameraTrigger()", error );
#else
   //
   // We are triggering the camera using an external hardware trigger.
   //
   error = flycaptureSetTrigger( 
      context, true, iPolarity, iSource, 0, 0 );
   _HANDLE_ERROR(error, "flycaptureSetCameraTrigger()" );

#endif

   // 
   // Poll the camera to make sure the camera is actually in trigger mode
   // before we start it (avoids timeouts due to the trigger not being armed)
   //
   checkTriggerReady( context );

   //
   // Start the camera and grab any excess images that are already in the pipe.
   // Although it is extremely rare for spurious images to occur, it is
   // possible for the grab call to return an image that is not a result of a
   // user-generated trigger. To grab excess images, set a zero-length timeout.
   // A value of zero makes the grab call non-blocking.
   //
   //printf( "Checking for any buffered images..." );
   error = flycaptureSetGrabTimeoutEx( context, 0 );
   _HANDLE_ERROR(error, "flycaptureSetGrabTimeoutEx()" );
      
   error = flycaptureStart(
      context, FLYCAPTURE_VIDEOMODE_ANY, FLYCAPTURE_FRAMERATE_ANY );
   _HANDLE_ERROR(error, "flycaptureStart()" );

   //
   // Grab the image immediately whether or not trigger present
   //
   error = flycaptureGrabImage2( context, &image );
   if( error == FLYCAPTURE_OK )
   {
      ;//printf( "buffered image found. Flush successful.\n" );
   }
   else if( error == FLYCAPTURE_TIMEOUT )
   {
      ;//printf( "no flush required! (normal behaviour)\n" );
   }
   else
   {
      _HANDLE_ERROR(error, "flycaptureGrabImage2()" );
   }

   error = flycaptureStop( context );
   _HANDLE_ERROR(error, "flycaptureStop()" );

}
int
main( int /* argc */, char** /* argv */ )
{
   TriclopsContext    triclops;
   TriclopsImage      disparityImage;
   TriclopsImage      refImage;
   TriclopsInput      triclopsInput;
   TriclopsROI*       pRois;
   int                nMaxRois;
   TriclopsError      te;

   FlyCaptureContext  flycapture; 
   FlyCaptureImage    flycaptureImage;
   FlyCaptureInfoEx pInfo;
   FlyCapturePixelFormat pixelFormat;
   FlyCaptureError    fe;

   int iMaxCols = 0;
   int iMaxRows = 0;
   
   // Create the camera context
   fe = flycaptureCreateContext( &flycapture );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureCreateContext()", fe );

   // Initialize the camera
   fe = flycaptureInitialize( flycapture, 0 );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureInitialize()", fe );

   // Get the camera configuration
   char* szCalFile;
   fe = flycaptureGetCalibrationFileFromCamera( flycapture, &szCalFile );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureGetCalibrationFileFromCamera()", fe );

   // Create a Triclops context from the cameras calibration file
   te = triclopsGetDefaultContextFromFile( &triclops, szCalFile );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetDefaultContextFromFile()", te );
   
   // Get camera information
   fe = flycaptureGetCameraInfo( flycapture, &pInfo );
   _HANDLE_FLYCAPTURE_ERROR( "flycatpureGetCameraInfo()", fe );
   
   if (pInfo.CameraType == FLYCAPTURE_COLOR)
   {
      pixelFormat = FLYCAPTURE_RAW16;
   } 
   else 
   {
      pixelFormat = FLYCAPTURE_MONO16;
   }
   
   switch (pInfo.CameraModel)
   {
   case FLYCAPTURE_BUMBLEBEE2:
      {
	 unsigned long ulValue;
	 flycaptureGetCameraRegister( flycapture, 0x1F28, &ulValue );
	 
	 if ( ( ulValue & 0x2 ) == 0 )
	 {
	    // Hi-res BB2
	    iMaxCols = 1024; 
	    iMaxRows = 768;   
	 }
	 else
	 {
	    // Low-res BB2
	    iMaxCols = 640;
	    iMaxRows = 480;
	 }
      }   
      break;
      
   case FLYCAPTURE_BUMBLEBEEXB3:
      iMaxCols = 1280;
      iMaxRows = 960;
      break;
      
   default:
      te = TriclopsErrorInvalidCamera;
      _HANDLE_TRICLOPS_ERROR( "triclopsCheckCameraModel()", te );
      break;
   }
 
   // Start grabbing
   fe = flycaptureStartCustomImage( 
      flycapture, 3, 0, 0, iMaxCols, iMaxRows, 100, pixelFormat);
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureStart()", fe );
   
   // Grab an image from the camera
   fe = flycaptureGrabImage2( flycapture, &flycaptureImage );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureGrabImage()", fe );

   // Extract information from the FlycaptureImage
   int imageCols = flycaptureImage.iCols;
   int imageRows = flycaptureImage.iRows;
   int imageRowInc = flycaptureImage.iRowInc;
   int iSideBySideImages = flycaptureImage.iNumImages;
   unsigned long timeStampSeconds = flycaptureImage.timeStamp.ulSeconds;
   unsigned long timeStampMicroSeconds = flycaptureImage.timeStamp.ulMicroSeconds;

   // Create buffers for holding the mono images
   unsigned char* rowIntColor = 
      new unsigned char[ imageCols * imageRows * iSideBySideImages * 4];
   unsigned char* rowIntMono = 
      new unsigned char[ imageCols * imageRows * iSideBySideImages ];

   // Create a temporary FlyCaptureImage for preparing the stereo image
   FlyCaptureImage tempColorImage;
   FlyCaptureImage tempMonoImage;
   
   tempColorImage.pData = rowIntColor;
   tempMonoImage.pData = rowIntMono;

   // Convert the pixel interleaved raw data to row interleaved format
   fe = flycapturePrepareStereoImage( 
      flycapture, flycaptureImage, &tempMonoImage, &tempColorImage );
   _HANDLE_FLYCAPTURE_ERROR( "flycapturePrepareStereoImage()", fe );

   // Pointers to positions in the mono buffer that correspond to the beginning
   // of the red, green and blue sections
   unsigned char* redMono = NULL;
   unsigned char* greenMono = NULL;
   unsigned char* blueMono = NULL;

   redMono = rowIntMono;
   if (flycaptureImage.iNumImages == 2)
   {
	   greenMono = redMono + imageCols;
	   blueMono = redMono + imageCols;
   }
   if (flycaptureImage.iNumImages == 3)
   {
	   greenMono = redMono + imageCols;
	   blueMono = redMono + ( 2 * imageCols );
   }
   
   // Use the row interleaved images to build up an RGB TriclopsInput.  
   // An RGB triclops input will contain the 3 raw images (1 from each camera).
   te = triclopsBuildRGBTriclopsInput(
      imageCols, 
      imageRows, 
      imageRowInc,  
      timeStampSeconds, 
      timeStampMicroSeconds, 
      redMono, 
      greenMono, 
      blueMono, 
      &triclopsInput);
   _HANDLE_TRICLOPS_ERROR( "triclopsBuildRGBTriclopsInput()", te );

  
   // Set up some stereo parameters:
   // Set to 640x480 output images
   te = triclopsSetResolution( triclops, 480, 640 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetResolution()", te );

   // Set disparity range to be quite wide
   te = triclopsSetDisparity( triclops, 0, 200 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetDisparity()", te );

   // Set subpixel interpolation off - so we know we don't need to use 
   // TriclopsImage16 structures when we access and save the disparity image
   te = triclopsSetSubpixelInterpolation( triclops, 0 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetSubpixelInterpolation()", te );
   
   
   // Get the pointer to the regions of interest array
   te = triclopsGetROIs( triclops, &pRois, &nMaxRois );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetROIs()", te );
   
   if( nMaxRois >= 4 ) 
   {
      // Set up four regions of interest: 
      
      // Entire upper left quadrant of image
      pRois[0].row   = 0;
      pRois[0].col   = 0;
      pRois[0].nrows = 240;
      pRois[0].ncols = 320;
      
      // Part of the lower right
      pRois[1].row   = 240;
      pRois[1].col   = 320;
      pRois[1].nrows = 180;
      pRois[1].ncols = 240;
      
      // Centered in upper right quadrant
      pRois[2].row   = 60;
      pRois[2].col   = 400;
      pRois[2].nrows = 120;
      pRois[2].ncols = 160;
      
      // Small section of lower left
      pRois[3].row   = 300;
      pRois[3].col   = 30;
      pRois[3].nrows = 80;
      pRois[3].ncols = 80;
      
      // Tell the TriclopsContext how many ROIs we want to process
      te = triclopsSetNumberOfROIs( triclops, 4 );
      _HANDLE_TRICLOPS_ERROR( "triclopsSetNumberOfROIs()", te );
   }
   else
   {
      printf( "Only %d ROIs available in the TriclopsContext "
	      "- this should never happen!\n"
	      "Aborting!\n",
	      nMaxRois );
	      
      // Destroy the Triclops context
      triclopsDestroyContext( triclops ) ;
      
      // Close the camera and destroy the context
      flycaptureStop( flycapture );
      flycaptureDestroyContext( flycapture );
      return 1;
   }
   
   
   // Rectify the images
   te = triclopsRectify( triclops, &triclopsInput );
   _HANDLE_TRICLOPS_ERROR( "triclopsRectify()", te );
   
   // Do stereo processing
   te = triclopsStereo( triclops );
   _HANDLE_TRICLOPS_ERROR( "triclopsStereo()", te );
   
   // Retrieve the disparity image from the Triclops context
   te = triclopsGetImage( triclops, 
			  TriImg_DISPARITY, 
			  TriCam_REFERENCE, 
			  &disparityImage );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetImage()", te );

   // Retrieve the rectified image from the Triclops context
   te = triclopsGetImage( triclops, 
			  TriImg_RECTIFIED, 
			  TriCam_REFERENCE, 
			  &refImage );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetImage()", te );

   // Save the disparity image
   te = triclopsSaveImage( &disparityImage, "disparity.pgm" );
   _HANDLE_TRICLOPS_ERROR( "triclopsSaveImage()", te );

   // Save the rectified image
   te = triclopsSaveImage( &refImage, "rectified.pgm" );
   _HANDLE_TRICLOPS_ERROR( "triclopsSaveImage()", te );

   // Delete the image buffer, it is not needed once the TriclopsInput
   // has been built
   delete [] rowIntMono;
   redMono = NULL;
   greenMono = NULL;
   blueMono = NULL;
   
   // Destroy the Triclops context
   triclopsDestroyContext( triclops ) ;
   
   // Close the camera and destroy the Flycapture context
   flycaptureStop( flycapture );
   flycaptureDestroyContext( flycapture );
   
   return 0;
}
예제 #6
0
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;
}
예제 #7
0
int
main( int /* argc */, char** /* argv */ )
{
   TriclopsError     te;
   FlyCaptureError   fe;
   TriclopsContext   triclops;
   FlyCaptureContext flycapture;

   float             baseline;
   int		     nrows;
   int               ncols;
   float             focalLength;

   TriclopsCameraConfiguration triclopsConfig;
   
   // Create the Flycapture context
   fe = flycaptureCreateContext( &flycapture );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureCreateContext()", fe );
   
   // Initialize the camera
   fe = flycaptureInitialize( flycapture, 0 );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureInitialize()", fe );
   
   // Get the camera configuration
   char* szCalFile;
   fe = flycaptureGetCalibrationFileFromCamera( flycapture, &szCalFile );
   _HANDLE_FLYCAPTURE_ERROR( "flycaptureGetCalibrationFileFromCamera()", fe );
   
   // Create a Triclops context from the cameras calibration file
   te = triclopsGetDefaultContextFromFile( &triclops, szCalFile );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetDefaultContextFromFile()", te );

   // Destroy the Flycapture context - this program just displays information contained
   // in the TriclopsContext
   flycaptureDestroyContext( flycapture );  

   printf( "Triclops Version  : %s\n", triclopsVersion() );
   
   // get the camera configuration 
   te = triclopsGetCameraConfiguration( triclops, &triclopsConfig );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetCameraConfiguration()", te );
   switch( triclopsConfig )
   {
      case TriCfg_L:
	 printf( "Configuration   : 3 Camera\n" );                   
	 break;
      case TriCfg_2CAM_HORIZONTAL:
	 printf( "Configuration   : 2 Camera horizontal\n" );                   
	 break;
      case TriCfg_2CAM_VERTICAL:
	 printf( "Configuration   : 2 Camera vertical\n" );                   
	 break;
      default:
	 printf( "Unrecognized configuration: %d\n", triclopsConfig ); 
   }
   
   // Get the baseline
   te = triclopsGetBaseline( triclops, &baseline );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetBaseline()", te );
   printf( "Baseline        : %f cm\n", baseline*100.0 );
   
   // Get the focal length
   te = triclopsGetFocalLength( triclops, &focalLength );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetFocalLength()", te );
   te = triclopsGetResolution( triclops, &nrows, &ncols );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetResolution()", te );
   
   printf( "Focal Length    : %f pixels for a %d x %d image\n", 
	   focalLength, 
	   ncols, 
	   nrows ) ;

   int   nRows, nCols;
   te = triclopsGetResolution( triclops, &nRows, &nCols );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetResolution()", te );

   float fCenterRow, fCenterCol;
   te = triclopsGetImageCenter( triclops, &fCenterRow, &fCenterCol );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetImageCenter()", te );

   printf( "The default image resolution for stereo processing is %d x %d\n",
	   nCols, nRows );
   printf( "For this resolution, the 'image center' or 'principal point' "
	   "is:\n" );
   printf( "Center Row = %f\n", fCenterRow );
   printf( "Center Col = %f\n", fCenterCol );

   
   // Destroy the Triclops context
   triclopsDestroyContext( triclops ) ;
   
   return 0;
}
예제 #8
0
//=============================================================================
// Main Program
//=============================================================================
int 
main( int /* argc */, char* /* argv[] */ )
{
   FlyCaptureError	error;
   FlyCaptureContext	context;
   FlyCaptureImage      image;

   printf( "Initializing camera.\n" );

   //
   // Create the context.
   //
   error = flycaptureCreateContext( &context );
   HANDLE_ERROR( "flycaptureCreateContext()", error );
      
   //
   // Initialize the first camera on the bus.
   //
   error = flycaptureInitialize( context, 0 );
   HANDLE_ERROR( "flycaptureInitialize()", error );

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

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

   //
   // Determine whether or not the camera supports external trigger mode.
   // If it does, put the camera into external trigger mode and otherwise 
   // exit.
   //
   bool bTriggerPresent;

   error = flycaptureQueryTrigger( 
      context, &bTriggerPresent, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
   HANDLE_ERROR( "flycaptureQueryTrigger()", error );

   if( !bTriggerPresent)
   {
      printf("This camera does not support external trigger... exiting\n");
      return 1;
   }

   int   iPolarity;
   int   iSource;
   int   iRawValue;
   int   iMode;

   error = flycaptureGetTrigger( 
      context, NULL, &iPolarity, &iSource, &iRawValue, &iMode, NULL );
   HANDLE_ERROR( "flycaptureGetTrigger()", error );

   printf( "Going into asynchronous Trigger_Mode_0.\n" );
   //
   // Ensure the camera is in Trigger Mode 0 by explicitly setting it, 
   // as the camera could have a different default trigger mode
   //
#ifdef SOFTWARE_TRIGGER_CAMERA
   //
   // We are triggering the camera using the internal software trigger.
   // If we are using the DCAM SOFTWARE_TRIGGER functionality, we must
   // change the Trigger_Source to reflect the Software Trigger ID = 7.
   //
   error = flycaptureSetTrigger( 
      context, true, iPolarity, 7, 0, 0 );
   HANDLE_ERROR( "flycaptureSetCameraTrigger()", error );
#else
   //
   // We are triggering the camera using an external hardware trigger.
   //
   error = flycaptureSetTrigger( 
      context, true, iPolarity, iSource, 0, 0 );
   HANDLE_ERROR( "flycaptureSetCameraTrigger()", error );

#endif

   // 
   // Poll the camera to make sure the camera is actually in trigger mode
   // before we start it (avoids timeouts due to the trigger not being armed)
   //
   checkTriggerReady( context );

   //
   // Start the camera and grab any excess images that are already in the pipe.
   // Although it is extremely rare for spurious images to occur, it is
   // possible for the grab call to return an image that is not a result of a
   // user-generated trigger. To grab excess images, set a zero-length timeout.
   // A value of zero makes the grab call non-blocking.
   //
   printf( "Checking for any buffered images..." );
   error = flycaptureSetGrabTimeoutEx( context, 0 );
   HANDLE_ERROR( "flycaptureSetGrabTimeoutEx()", error );
      
   error = flycaptureStart(
      context, FLYCAPTURE_VIDEOMODE_ANY, FLYCAPTURE_FRAMERATE_ANY );
   HANDLE_ERROR( "flycaptureStart()", error );

   //
   // Grab the image immediately whether or not trigger present
   //
   error = flycaptureGrabImage2( context, &image );
   if( error == FLYCAPTURE_OK )
   {
      printf( "buffered image found. Flush successful.\n" );
   }
   else if( error == FLYCAPTURE_TIMEOUT )
   {
      printf( "no flush required! (normal behaviour)\n" );
   }
   else
   {
      HANDLE_ERROR( "flycaptureGrabImage2()", error );
   }

   error = flycaptureStop( context );
   HANDLE_ERROR( "flycaptureStop()", error );

   //
   // Start camera.  This is done after setting the trigger so that
   // excess images isochronously streamed from the camera don't fill up 
   // the internal buffers.
   //
   printf( "Starting camera.\n" );
   error = flycaptureStart( 
      context, 
      FLYCAPTURE_VIDEOMODE_ANY,
      FLYCAPTURE_FRAMERATE_ANY );
   HANDLE_ERROR( "flycaptureStart()", error );

   //
   // Set the grab timeout so that calls to flycaptureGrabImage2 will return 
   // after TIMEOUT milliseconds if the trigger hasn't fired.
   //
   error = flycaptureSetGrabTimeoutEx( context, TIMEOUT );
   HANDLE_ERROR( "flycaptureSetGrabTimeoutEx()", error );

   printf( "This program will quit after %d images are grabbed.\n", IMAGES );

#ifndef SOFTWARE_TRIGGER_CAMERA
   printf( "Trigger the camera by sending a trigger pulse to GPIO%d.\n", 
      iSource );
#endif

   for( int iImage = 0; iImage < IMAGES; iImage++ )
   {

#ifdef SOFTWARE_TRIGGER_CAMERA

#ifdef USE_SOFT_ASYNC_TRIGGER
      //
      // Check that the camera actually supports the PGR SOFT_ASYNC_TRIGGER
      // method of software triggering
      //
      error = checkSoftwareTriggerPresence( context, SOFT_ASYNC_TRIGGER );
      if( error == FLYCAPTURE_OK )
      {
         checkTriggerReady( context );
         
         //
         // Camera is now ready to be triggered, so generate software trigger
         // by writing a '0' to bit 31
         //
         printf( "Press the Enter key to initiate a software trigger.\n" );
         getchar();
         error = flycaptureSetCameraRegister( 
            context, SOFT_ASYNC_TRIGGER, 0x80000000 );
         HANDLE_ERROR( "flycaptureSetCameraRegister()", error );
      }
      else
      {
         printf( "SOFT_ASYNC_TRIGGER not implemented! Grab will timeout.\n" );
      }
#else
      //
      // Check that the camera actually supports the DCAM SOFTWARE_TRIGGER
      // method of software triggering    
      //
      error = checkSoftwareTriggerPresence( context, SOFTWARE_TRIGGER );
      if( error == FLYCAPTURE_OK )
      {
         error = checkTriggerReady( context );
         
         //
         // Camera is now ready to be triggered, so generate software trigger
         // by writing a '1' to bit 0
         //
         printf( "Press the Enter key to initiate a software trigger.\n" );
         getchar();
         error = flycaptureSetCameraRegister( 
            context, SOFTWARE_TRIGGER, 0x80000000 );
         HANDLE_ERROR( "flycaptureSetCameraRegister()", error );
      }
      else
      {
         printf( "SOFTWARE_TRIGGER not implemented! Grab will timeout.\n" );
      }
#endif

#endif
      //
      // Do an image grab.  This call will block until the camera
      // is externally triggered.
      //
      error = flycaptureGrabImage2( context, &image );
      if( error == FLYCAPTURE_TIMEOUT )
      {
	 printf( "Grab #%d timed out after %d milliseconds.\n", iImage, TIMEOUT );
      }
      else if( error != FLYCAPTURE_OK )
      {
	 HANDLE_ERROR( "flycaptureGrabImage2()", error );
      }      
      else
      {
	 printf( "Grab %d successful!\n", iImage );	 
      }
   }   

   //
   // Stop the camera and destroy the context.
   //
   flycaptureStop( context );
   flycaptureDestroyContext( context );

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

   return 0;
}
예제 #9
0
void ofxffmv::initFFMV(int wid,int hei, int rate,int startX,int startY )
{
	//camNum= 1;
	/*
    for(int i=0;i<camNum;i++)
    {
	*/
		std::cout <<"initFFMV.Camera:" << fcCameraID << std::endl ;
    //
	// Create the context. This call must be made before any other calls to
	// to the context are made, as a valid context is needed for all
	// camera-specific FlyCapture library calls. This call sets the context
	// to the default settings, but flycaptureInitialize() must be called
	// below to fully initialize the camera for use.
	flycaptureCreateContext( &context[0] );
	printf("initFFMV.A\n");
	//
	// Initialize the camera. This call initializes one of the cameras on the
	// bus with the FlyCaptureContext that is passed in. This should generally
	// be called right after creating the context but before doing anything
	// else.
	//
	// This call performs several functions. It sets the camera to communicate
	// at the proper bus speed, turns on color processing (if available) and
	// sets the Bayer orientation to the correct setting. Finally, it also
	// initializes the white balance tables for cameras that support that
	// function.
	//
	//flycaptureInitialize( context[i], i );
	flycaptureInitialize( context[0], fcCameraID );
	printf("VinitFFMV.B\n");



	//now we load the camera settings from the Memory Channel. With this we could manage the settings in the flycap.exe and save the data into the channel for later use

	unsigned int puiCurrentChannel;
	unsigned int puiNumChannels;

	//flycaptureGetMemoryChannel(FlyCaptureContext  context,unsigned int*     puiCurrentChannel,unsigned int*     puiNumChannels )
	flycaptureGetMemoryChannel(context[0], &puiCurrentChannel, &puiNumChannels );
	std::cout <<"puiCurrentChannel:"<<puiCurrentChannel<<"| puiNumChannels:"<<puiNumChannels << std::endl;

		//flycaptureRestoreFromMemoryChannel(FlyCaptureContext  context,unsigned long     ulChannel );
	if(fcMemoryChannel != NULL && fcMemoryChannel <= puiNumChannels){
		std::cout <<"Using XML Data for Memory Channel:"<<fcMemoryChannel << std::endl;
		flycaptureRestoreFromMemoryChannel(context[0],fcMemoryChannel);
	}else if (puiCurrentChannel != NULL) {
		std::cout <<"Using puiCurrentChannel Data for Memory Channel:"<<puiCurrentChannel << std::endl;
		flycaptureRestoreFromMemoryChannel(context[0],puiCurrentChannel);
	}
//-----------------------------------

	//
	// Start grabbing images in the current videomode and framerate. Driver
	// level image buffer allocation is performed at this point. After this
	// point, images will be constantly grabbed by the camera and stored
	// in the buffers on the PC.
	/*
	if(wid==640)
	flycaptureStartCustomImage(context[i],0,startX,startY,640,480,100,FLYCAPTURE_MONO8);
	else if(wid==320)
	flycaptureStartCustomImage(context[i],1,startX,startY,320,240,100,FLYCAPTURE_MONO8);
	flycaptureGrabImage2( context[i], &fcImage[i] );
	*/

	//http://nuigroup.com/forums/viewthread/6643/#42007

	FlyCaptureVideoMode videoMode;
    switch(wid)
    {
        case 640:
            videoMode = FLYCAPTURE_VIDEOMODE_640x480Y8;
            break;
        case 800:
            videoMode = FLYCAPTURE_VIDEOMODE_800x600Y8;
            break;
        case 1024:
            videoMode = FLYCAPTURE_VIDEOMODE_1024x768Y8;
            break;
        case 1280:
            videoMode = FLYCAPTURE_VIDEOMODE_1280x960Y8;
            break;
        case 1600:
            videoMode = FLYCAPTURE_VIDEOMODE_1600x1200Y8;
            break;
        default:
            videoMode = FLYCAPTURE_VIDEOMODE_640x480Y8;
    }

    FlyCaptureFrameRate frameRate;
    switch(rate)
    {
        case 15:
            frameRate = FLYCAPTURE_FRAMERATE_15;
            break;
        case 30:
            frameRate = FLYCAPTURE_FRAMERATE_30;
            break;
        case 60:
            frameRate = FLYCAPTURE_FRAMERATE_60;
            break;
        case 120:
            frameRate = FLYCAPTURE_FRAMERATE_120;
            break;
        case 240:
            frameRate = FLYCAPTURE_FRAMERATE_240;
            break;
        default:
            frameRate = FLYCAPTURE_FRAMERATE_30;
    }

    bool result;
    flycaptureCheckVideoMode(context[0], videoMode, frameRate, &result);
	printf("VinitFFMV.C\n");
    if(result)
    {
        flycaptureStart(context[0], videoMode, frameRate);
		printf("VinitFFMV.D\n");
       // flycaptureGrabImage2(context[i], &fcImage[i] );
		printf("VinitFFMV.E\n");
    }
    else printf("Video mode not supported\n");

	flycaptureGrabImage2( context[0], &fcImage[0] );//Für getWidth()/Hight()
	//camWidth=fcImage.iCols;
	//camHeight=fcImage.iRows;
   // }//end of for loop
	printf("VinitFFMV.F\n");
}