Package: camera-management
camera-managementThis is a low level way of interacting with multiple cameras connected to different devices. If you want to contribute
please have a look at theDEV_README.InstallationUse the following command to install the package:pipinstallcamera-managementIf you want to use AVT-Cameras or any camera that uses the Vimba / VimbaX backend, please read the section about AVT
Cameras below.UsageThis package aims to provide an easy networking solution for communicating with multiple Webcams and other Cameras. A
basic example is shown below, more examples can be found
onGitHub:Set up and start theManagerAppon the backend device, meaning the device with all the connected cams you want to
use.fromcamera_management.camera_management_app.manager_interfaceimportManagerAppfrompathlibimportPathmanager_backend=ManagerApp(path_to_configs=Path(__file__).parent/"data",autostart=True)manager_backend.start()The directory containing the configs (the argumentpath_to_configsof theManagerApp) should look like this:├──individual_configs
│├──config1.json
│└──config2.json
└──type_configs├──config1.json├──config2.json├──otherconfig.json└──config3.jsonOn a detailed explanation on how the configs work and how to build your own config see the section "configs" below. The
config name can be anything you want.Set up and start themanager_interfaceon the frontend device, meaning the device you want to use the camera
stream at.
You need to supply the IP address of the backend device. The port should always be8090. If the front- and
backend are the same device, the host IP will be127.0.0.1.fromcamera_management.frontends.basic_frontendimportmanager_interfacemanager_frontend=manager_interface(host="127.0.0.1",port=8090,autostart=True)Use themanager_frontendto get an actual camera interface. The manager only manages the cameras, but it does not
provide any streams. It only provides the interfaces to the actual camera streams# Get all ports of the actual configured camerascamera_infos=manager_frontend.get_configured_cams(verbose=True)The command above might print something like:CAM TYPE               CAM SERIAL            CONFIG TYPE    CONFIG INDIVIDUAL      PORT  PORT ACTIVE    CALIBRATION AVAILABLE
---------------------  --------------------  -------------  -------------------  ------  -------------  -----------------------
4K USB CAMERA          12567                 True           False                  8091  True           False
webcam                 V011R007C001B004      True           False                  8092  True           FalseUse this information to choose the camera you want to access.# Get a camera interface by its portcamera_interface=manager_frontend.get_interface_by_port(8091)Display the camera streamwhileTrue:data=camera_interface.fetch_image_data()cv2.imshow("Stream",data.image)ifcv2.waitKey(20)==ord("q"):breakThe above while loop continuously polls the latest image from the camera backend and displays it using OpenCV. The
functionfetch_data()is a convenience
function, the same result can be achieved using the code below, using requests.importrequestsimportpickleimportcv2host='127.0.0.1'port=8090whileTrue:try:response=requests.get(f"http://{host}:{port}/data/imageProcessor")exceptrequests.exceptions.ConnectionError:continueifresponse.status_code==200:cv2.imshow("Moin",pickle.loads(response.content).image)ifcv2.waitKey(20)==ord("q"):breakChange camera settings. You can use the convenience functionset_general_settingto set camera settings. Since this
library works for
a range of vastly different cameras, not every setting can be applied to each camera. Check your specific camera to
see, if a specific settings is applicable.
Below is an example of setting theCAP_PROP_FRAME_WIDTHproperty, meaning the width of the output image
to400px. Afterward, the settings is read usingget_general_setting. Finally, the current active camera description is shown using thedescriptionproperty of
the camera interface.Important: When using the convenience functionset_general_setting, the setting is automatically read back, so you
can see if it was successful.fromcamera_managementimportSETTINGSprint(camera_interface.set_general_setting(SETTINGS.CAP_PROP_FRAME_WIDTH,400))print(camera_interface.get_general_setting(SETTINGS.CAP_PROP_FRAME_WIDTH))print(camera_interface.description)ConfigA valid config can be created using the following code. It will create config files for every currently connected cam
and save them to the supplied directory.frompathlibimportPathfromcamera_management.tools.create_descriptionimportcreate_basic_descriptioncreate_basic_description(Path('<PATH_WHERE_CONFIG_SHOULD_BE_STORED>'),type_calib=True)This will create valid, yet empty description files in the given directory. An explanation for thetype_calib=Trueflag is given below.
A valid description file might look like this:{"information":{"standard_resolution":{"x":1920,"y":1080,"channels":3},"available_resolutions":[{"x":1920,"y":1080,"channels":3}],"device":{"path":0,"vendor_id":"0x4f2","product_id":"0xb79e","vendor":"SunplusIT Inc","product":"USB2.0 FHD UVC WebCam","serial":null,"backend":1200,"transp_type":"usb ","unique_id":"0x14000004f2b79e","device_type":"AVCaptureDeviceTypeExternalUnknown","is_used":false},"resolution_roi_coupled":false},"calibration":{"mode":"type","available":false,"values":null,"model":null},"config":{},"debug":{"last_updated":"22-01-2024 16:35:47","created_on_platform":"darwin"}}information: Contains general information about a camerastandard_resolution: Contains the desired resolution of the output streamavailable_resolutions: Contains all available resolutions of the cameradevice: Contains all the relevant information to identify acamera typeor anindividual camera.resolution_roi_coupled: Is the resolution coupled to the ROI (region of interest)? Can be different for different
camerascalibration: Calibration information and values. Can be atypeorindividualcalibration.mode: A type calibration is a set of general calibration parameters for a certain camera type, where as an
individual calibration is linked to a specific (individual) cameraavailable: Are there calibration values?values: The actual calibration values. Should be empty when 'available' is set to False and should contain values,
if 'available' is set to True.
The actual values can be different, depending on the chosen calibration modelmodel: The chosen calibration model (can be 'OpenCV_standard' or 'brown' at the moment)config: The initial camera settings. Leave empty if you don't want to set them. This field is dict containing initial
camera settings given as akey: valuepair (e.g. '3: 400' -> This sets the image width to 400)debug: Information to debug a description file (Please don't change those manually)last_updated: The last time this file was updatedcreated_on_platform: The platform this file was created onKnown IssuesWhen using Cameras with a large resolution the framerate might be very lowWhen using multiple USB 2.x cameras connected to the manager device using an USB Hub some might not work, since the
data rate of USB 2.x is limited.AVT CamerasAVT (Allied Vision Technologies) Cameras or all other cameras that use the Vimba or VimbaX backend are supported in this
project, but need to be set up manually, since
the Vimba / Vimba X python wrapper currently doesnotsit on pypi. Vimba X is currently the most recent version of
Vimba.
Although it shares many features with Vimba it is a standalone release. The python wrapper for Vimba X is
calledVmbPy(not to be confused with Vimba Python, which is the Python wrapper for Vimba - without X). To install VmbPy you have to
follow the instructionshere.Warning:VmbaPy is not very stable at the moment and does require some tweaks to run on Linux with Ethernet Cams.