Opening a Camera
In the Connecting to Devices guide, we explained how cameras are detected and how camera plugins are required. Let’s now see how to open a camera with the SDK.
Using HAL C++ API
A camera can be opened using the function Metavision::DeviceDiscovery::open()
:
device = Metavision::DeviceDiscovery::open(serial_number);
The serial_number
can be given in the following forms:
Empty String: this will use the first available plugin compatible with a connected device
DeviceID: this will open the specified device using the first compatible plugin
Name:DeviceID: this will open the specified device using the first plugin with matching Integrator or Plugin name
IntegratorName:PluginName:DeviceID: this will open the specified device ID using the specified plugin. The fields IntegratorName or PluginName can be empty, and if so, are ignored.
The first plugin that fulfills the requirements of the Integrator’s name and the Plugin’s name and that is able to open the DeviceID is used to open the device. As a camera device may be supported by several plugins, you may want to specify the plugin to be used by Integrator or Plugin name.
Also, note that the camera initialization can be customized by providing a configuration structure
to the Metavision::DeviceDiscovery::open()
function.
See also
See metavision_hal_ls sample showing how to discover and open cameras.
Using SDK Stream C++ API
HAL API shown above is a good starting point to start programming event-based sensor. This API gives access to all the features of the sensor and the camera. Though if you want to build a full-featured application (with display, data conversion etc.) you might consider our other APIs that are built on top of HAL but offer another layer of abstraction and some other features. (see our SDK Architecture page to understand this layered approach).
So, to code in C++, you might consider using the SDK Stream module that offers a user-friendly
API to access the camera and the data with the Camera
class.
Essentially, the simplest way to open a device with the Camera
class
is to let the class find the first available device:
camera = Metavision::Camera::from_first_available();
To see, how to use the camera
object to tune your sensor, start the device and retrieve the event stream,
you can check our other programming guides or follow the tutorial Get Started using C++.
See also
It is also possible to open a device using the Python Camera class
(Binding of the C++ Camera
class) as illustrated in
the metavision_camera_stream_slicer Python sample.
Using SDK Core Python API
To code in Python, you could use the Python bindings of the HAL C++ API
as explained in the metavision_hal_get_started sample,
but the easiest starting point is to use the EventsIterator
class
that allows to connect to the device, start it and retrieve buffer of event data produced by the camera.
Essentially, the following statement will connect to the first available device:
mv_iterator = EventsIterator("")
To see how to use this iterator to tune your sensor and retrieve the event stream, you can check our other programming guides or follow the tutorial Python Get started.