Camera properties are not immediately updated

I want to change the image format, e.g. the width. I can do so, but then if I start image acquisition the grabbed image has still the old format. Only when I run the script a second time the actual image format has changed.
What am I doing wrong?

Here is a minimal example:

import cvb as cvb
import numpy as np

# load the camera
vin_device = cvb.DeviceFactory.open(cvb.install_path() + "/drivers/GenICam.vin")
device_node_map = vin_device.node_maps["Device"]

# set width to 1000
device_node_map.Width.value = 1000
print(device_node_map.Width.value)

stream = vin_device.stream
stream.start()
image,status = stream.wait_for(500)
if status == cvb.WaitStatus.Ok:
    print(np.asarray(image).shape)   
stream.try_stop()

I use Python version 3.6.5 and CVBpy version v13.01.000.

1 Like

Dear @babaf

You have to tell the driver that the image format has changed.
See this post with some more information:
https://forum.commonvisionblox.com/t/pixel-format-doesnt-match-output/438/2?u=sebastian

The ImageRect Class with its update() function is the equivalent for CVBpy.

THANKS!
Including vin_device.image_rect.update(0) after setting the new width did the job!

1 Like

Hi @babaf,

I would suggest to write the call a little different so it becomes more verbose.

python vin_device.image_rect.update(mode = cvb.DeviceUpdateMode.UpdateDeviceImage)

This call is actually equivalent to:

So you may wonder if why like typing so much :wink: - I don’t, but picking the wrong mode can be dangerous so I suggest to be as explicit as possible here!

For your simple script, it does not really matter which mode you choose.

However, if you hold a reference to the vin_device.device_image the mode is used to choose if the buffer for the device image is reallocated (UpdateDeviceImage) or if the device image is detached from the device and a new device image is associated with it (NewDeviceImage).

Detaching the device image is the right choice if you currently have access to the device image buffer (e.g. though numpy). If not you would get an access violation error because the old buffer will be freed during the update process. Whereas detaching actually transfers the buffer ownership to the old device image so accessing it will remain safe.

2 Likes