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.
So you may wonder if why like typing so much - 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.