|SDK Version Compatibility||Language||Date First Posted||Primary Library Calls||Link|
The PGRFlyCaptureTest sample program is a simple program designed to report information related to all compatible cameras attached to the host system, capture a series of images from a single camera, record the amount of time taken to grab these images, then save the last image in the current directory.
The program first creates two FlyCapture variables, one of which is aFlyCaptureError variable. In order to reliably debug your application, define a variable of this type to capture meaningful errors returned by API functions.
The program begins by calling flycaptureBusEnumerateCamerasEx(). This enumerates, or lists, all PGR cameras sitting on the bus and their bus index, starting at zero. This function does not enumerate non-PGR cameras.
A FlyCaptureContext is created by calling flycaptureCreateContext(). This acts as a handle to the camera, and is required to initialize and start the camera. All camera specific function calls in the FlyCapture library require a valid context in order to succeed. The program then initializes the camera located at bus index zero and associates it with the camera context by calling flycaptureInitialize().
Multiple cameras connected to the FireWire bus are enumerated at bus indices (FireWire nodes) that start at 0. Information related to the initialized camera (model, serial number, DCAM compliance, etc.) can be retrieved at this time by flycaptureGetCameraInfo().
The initialized camera is then started at the default resolution and image and frame rate of the camera. This function also (silently) allocates four buffers in main memory that are used to hold the images that are streamed in from the camera. Once a camera has been started, it immediately begins capturing and streaming images via Direct Memory Access (DMA) to these memory buffers. Once these buffers are full, they are overwritten with consecutive images unless they are locked by the user.
The program then creates a FlyCaptureImage variable. The FlyCaptureImage structure contains the image data, as well as video mode, whether the image is stippled (color) and timestamp information.
In the grab loop, when a call to flycaptureGrabImage2() is made, a pointer to the image buffer (&image) with the newest (latest) complete image is returned. The call to flycaptureGrabImage2() does not involve copying, so it is quite fast. The user is never given an image that is older than one that has already been seen. Once the pointer to the buffer is returned to the user, this buffer remains locked until flycaptureGrabImage2() is called again. If no buffer contains an image newer than the last returned, then the flycaptureGrabImage2() call blocks until a new image is available.
After the program exits the grab loop, it converts the last image grabbed to a 32-bit per pixel image that can be displayed by Microsoft Windows (which uses the BGRU format) by calling flycaptureConvertImage(). If the camera is not a color camera, Y8 and Y16 images are converted to BGRU greyscale. flycaptureSaveImage() is then called to save the converted BGRU image as a PPM. The raw image is also saved by calling the same function but passing in FLYCAPTURE_FILEFORMAT_PGM as the argument.
Finally, the program stops the camera using flycaptureStop(). This is followed by flycaptureDestroyContext(), which destroys the camera context. In order to prevent memory leaks from occurring, this function must be called when the user is finished with the FlyCaptureContext.
|*Note||To run PGRFlyCaptureTestCSharp,
must enable the unsafe option. To do so:
To run the executable after compiling, you must change the .NET Security settings as follows:
Start->Settings->Control Panel->Administrative Tools->Microsoft .NET Framework 1.1 Wizards->Adjust .NET Security->Make changes to this computer->My Computer->Full Trust
Return to List of Examples