VimbaPython
VimbaPython copied to clipboard
cRuntime error when opening multiple instances of Vimba (?)
Hi,
This is more of a support question than a bug I think. Basically, I want to implement a Wrapper around Vimba Camera, to allow me to use it as a opencv camera. This is done like the following:
Wrapper code
class VimbaCameraWrapper:
# implemented to mimic opencv capture interface, aka a .read method
vimba_camIndex = None
def __init__(self, camIndex):
"""
# TODO set cam settings like this
cam.ExposureTime.set(1000)
cam.Height.set(480)
cam.Width.set(640)
"""
self.vimba_camIndex = camIndex
def read(self):
try:
with Vimba.get_instance() as vimba:
cams = vimba.get_all_cameras()
with cams[self.vimba_camIndex] as cam:
frame = cam.get_frame()
opencv_frame = frame.as_opencv_image()
self.last_frame = opencv_frame
return (1, opencv_frame)
except KeyboardInterrupt:
sys.exit("User exit")
except:
print("Error capturing frame")
return (1, self.last_frame)
But this does not work reliably, after some time I get:
09-23-2021 14:34:35.578 [E] cRuntime - failed to parse document (Failed to read Element name)
09-23-2021 14:34:35.596 [T] cCameraActor - failed to setup features
This can be reproduced with the following script:
import cv2
from vimba import *
import time
while True:
with Vimba.get_instance() as vimba:
cams = vimba.get_all_cameras()
with cams[0] as cam:
before = time.time()
frame = cam.get_frame()
print("took second to get frame:", time.time() - before)
opencv_frame = frame.as_opencv_image()
Can you please point me how to properly implement this? I know I could go to multithreading, but that adds a lot of complexity. Thank you!
The above error when opening multiple instances of Vimba , this is caused when a camera is opened in vimba and you are trying to open the camera again from another application. The camera can only be opened in full mode only once.
Is it possible to send us the whole code so that we can try to test it at our side.
@arunprakash-avt Thanks for the swift reply, the script in the original post is the smallest way to reproduce, here is my entire script:
import sys
from vimba import *
class VimbaCameraWrapper:
# implemented to mimic opencv capture interface, aka a .read method
vimba_camIndex = None
last_frame = None
def __init__(self, camIndex):
"""
# TODO set cam settings like this
cam.ExposureTime.set(1000)
cam.Height.set(480)
cam.Width.set(640)
"""
self.vimba_camIndex = camIndex
def read(self):
try:
with Vimba.get_instance() as vimba:
cams = vimba.get_all_cameras()
with cams[self.vimba_camIndex] as cam:
frame = cam.get_frame()
opencv_frame = frame.as_opencv_image()
self.last_frame = opencv_frame
return (1, opencv_frame)
except KeyboardInterrupt:
sys.exit("User exit")
except:
print("Error capturing frame")
return (1, self.last_frame)
def get_vimba_cameras():
with Vimba.get_instance() as vimba:
cams = vimba.get_all_cameras()
# Wrap all cams in VimbaCameraWrapper
wrapped_cams = [VimbaCameraWrapper(camIndex) for camIndex in range(len(cams))]
return wrapped_cams
if __name__ == "__main__":
available_cameras = get_vimba_cameras()
cam_wrapper = available_cameras[0]
while True:
_, frame = cam_wrapper.read()
print("got frame")
I would like to know which camera and operating system your are using.
I am using the Alvium 1800 U-158 and running on ARM64 Ubuntu (Raspberry pi 4)
I request you to check if the controller port is USB 3. The performance of the Raspberry pi 4 controller is not so good. This could be the cause of the above issue.
@arunprakash-avt That is definitely not the problem, it is in a USB 3.0 port. The viewer application also works fine, and when using the example programs provided in this repo I can get frames at a higher rate and without errors, thus it must be a programming error. I think it has something to do with not closing the instance correctly but I'm not sure.
Edit: can't you reproduce the error on normal hardware?
I could not reproduce this error in an normal hardware. I just tested in Windows PC with Alvium 1800 U-158. I have configured the camera Device link throughput limit to 300 Mbit/s.