Tuning the camera settings

Event-based sensors provide multiple functionalities (ROI, Anti-Flicker, ERC…) and tunings (e.g. biases). Let’s see how we can access them programmatically.

Using HAL C++ API

As explained in the Architecture page, HAL gives access to Facilities that expose the various camera functionalities.

Once we are connected to a camera, we can access the functions of the facilities. For example, here is how to set an Anti-Flicker in the frequency range [90Hz, 110Hz]:

auto anti_flicker = device->get_facility<Metavision::I_AntiFlickerModule>();
anti_flicker->set_frequency_band(90,110);
anti_flicker->enable(true);

To see that kind of call in action on multiple facilities, check the metavision_hal_showcase sample.

Using SDK Stream C++ API

With the Camera class, it is not only possible to adjust camera settings, but we can also save the current state of all the camera settings in a file and initiate the camera settings from a similar file.

Setting the camera settings

Once we opened a camera using the Camera class, if we want to configure the sensor Anti-Flicker similarly to what was shown in the previous section, we have to use get the device from the camera with get_device():

auto *anti_flicker = camera.get_device().get_facility<Metavision::I_AntiFlickerModule>();
anti_flicker->set_frequency_band(90,110);
anti_flicker->enable(true);

To see that kind of call in action check the metavision_viewer sample.

Saving/loading the camera settings

There are multiple scenarios where you would like to save the camera settings in a file:

  • you tuned your camera using Metavision Studio (adjusted the biases, set an ROI, enabled an hardware filter etc.), you want to re-use those settings in some other applications like testing some algorithms with our Advanced modules Samples.

  • you want to perform some recordings using Metavision Viewer that require some camera settings that are currently not available as command line option or UI interaction.

  • you are using multiple cameras that require some specific settings

  • etc.

To create those camera settings file without writing any code, you can use:

To manage the camera settings programmatically, SDK Stream C++ API offers 2 functions of the Camera class (that can be seen in action in Metavision Viewer sample):

  • save(path)

  • load(path)

The camera settings are saved in a JSON file that you can also manually edit as long as you respect the structure. For example, here is a JSON setting files that will set a RONI window (Region of Non Interest) of size 50,50 at coordinates 100,200 and that will set bias_fo to 11:

{
 "roi_state": {
  "window": [
   {
    "x": 100,
    "y": 200,
    "width": 50,
    "height": 50
   }
  ],
  "columns": [],
  "rows": [],
  "enabled": true,
  "mode": "RONI"
 },
 "ll_biases_state": {
  "bias": [
   {
    "name": "bias_fo",
    "value": 11
   }
  ]
 }
}

Using SDK Core Python API

To configure a camera using the SDK Core Python API, the easiest way is to create the device before creating the EventsIterator. This way we can access the facilities on the device. For example, to configure the sensor Anti-Flicker similarly to what was shown in the previous section:

# first we create a HAL device
device = initiate_device("")
device.get_i_antiflicker_module().set_frequency_band(90,110)
device.get_i_antiflicker_module().enable(True)

# then we create an EventsIterator from the Device
mv_iterator = EventsIterator.from_device(device=device)

To see such a procedure in action, you can for example check the metavision_psm sample.

Note

If you are using the lower level HAL Python API as shown in the metavision_hal_get_started sample configuring the camera is done in a similar way as soon as you created your device object:

device = DeviceDiscovery.open("")
device.get_i_antiflicker_module().set_frequency_band(90,110)
device.get_i_antiflicker_module().enable(True)