![]() |
Imaging Control 4 C Library
1.3.0
|
This article shows in detail how to set up a data stream from a video capture device and grab a single image.
First, the library is initialized, and the first available video capture device is opened:
Opening the device can fail, so we check for the return value of the function. In case of an error the last error is printed. For details on error handling, see Error Handling.
Then, the device has to be configured. This step is important because in most situations, programs want the camera to be in a defined state before starting operation. In this example, the resolution is configured using the device's IC4_PROPID_WIDTH and IC4_PROPID_HEIGHT properties:
At this point, an application could also load a prepared device configuration file (using ic4_grabber_device_open_from_state_file or apply a serialized property configuration using ic4_propmap_deserialize).
After the device has been configured, it is time to setup a data stream. To receive image data from the video capture device, a Sink object has to be created. The Snap Sink is the sink most suitable to grab images on demand.
The data stream is established by calling ic4_grabber_stream_setup, passing the sink as a parameter. We also set the start_acquisition parameter to true
, so that the device is instructed to start image acquisition immediately after the data stream was created.
After the streamSetup call returned successfully, the device is continuously sending images to the host computer.
By calling ic4_snapsink_snap_single, the sink is instructed to wait for the next image to arrive at the sink and, if an image is received during the specified timeout period, return it:
In this example, we print information about the received image and save it in a bitmap file.
A call to ic4_grabber_stream_stop stops the data stream:
Stopping acquisition and data stream is important, because keeping the acquisition active would waste CPU and memory resources as well as bandwidth on the transmission medium.