![]() |
PVCAM
3.9.x
Programmable Virtual Camera Access Method library
|
This example shows how to setup and run camera in continuous circular buffer mode with callback notifications.
This is the preferred acquisition mode for obtaining the highest camera frame rate. Using large circular buffer also allows PVCAM to provide basic load balancing that is essential for reliable frame delivery when the system experiences temporary intervals of high resource usage. This is crucial for very high camera frame rates where the circular buffer should be large enough to hold at least 500ms of acquisition or more, taking into account other tasks the system might be executing during the acquisition.
Please note that both PVCAM or the camera can still decide to skip frames if the transfer interface is busy or the circular buffer starts overrunning due to application not being able to process the callbacks. In such case, the application can detect these events by tracking the FRAME_INFO
FrameNr
or the frame number provided by Embedded Frame Metadata feature.
This sample code collects 50 frames and stops automatically. However, the live mode is often used for image preview and is usually stopped by a UI event such as user pressing a 'Stop' button or similar.
Unlike the Single Image Callbacks, this example uses custom callback handler instead of a generic one defined in the common code part. The implementation is similar, we only added custom counters inside the SampleContext
structure:
Because the callback handler is invoked by PVCAM from a different thread than the main
thread, printing to standard output should be properly synchronized. Otherwise the text printed from multiple threads could be interleaved and output formatting could become broken. For simplicity, this code sample relies on relatively low camera frame rate and basic synchronization with the eofEvent
.
The code snippet below initializes PVCAM and opens the first available camera. Please, refer to the actual code sample in the SDK installation directory for more details about the common helper functions used in this documentation.
Register a callback handler to receive a notification when EOF event arrives. Similar handler is implemented in the common Frame Callback Handler section used across the SDK examples. However, additionally to the usual CameraContext, this specific example also uses two custom counters:
Prepare the continuous acquisition with circular buffer mode. The pl_exp_setup_cont function returns the size of one frame (unlike the pl_exp_setup_seq which returns the full buffer size). See more in Acquisition Configuration section.
Now allocate the buffer memory. The application is in control of the circular buffer and should allocate memory of appropriate size.
Start the continuous acquisition. By passing the entire size of the buffer to pl_exp_start_cont, PVCAM can calculate the capacity of the circular buffer.
Loop to acquire 50 frames:
Here we need to wait for a frame readout notification signaled by the eofEvent
in the CameraContext which is raised in the callback handler we registered. If the frame does not arrive within 5 seconds or if user aborts the acquisition with ctrl+c keyboard shortcut, the main while
loop is interrupted and the acquisition is aborted.
Print basic information from the FRAME_INFO structure and display the frame.
Once we have acquired the desired number of frames, the continuous acquisition should be stopped with pl_exp_abort function. For more information about closing cameras and uninitializing PVCAM, please, refer to the Closing Camera and Uninitializing PVCAM section.