Provides a Python-based web-server REST API to connect to a Basler camera (using PyPylon)
It uses FastAPI to spin up a minimal web server that wraps the Python-package pypylon in a web-api. (This again wraps the Pylon Camera Software Suite into a Python-package.)
The new sever can be packaged as a virtual (Docker) container. Find released images on DockerHub under https://hub.docker.com/u/maxscw.
The repository is structured as follows:
BaslerCameraAdapter
+-- docs <- auxiliary files for documentation (basically screenshots)
|-- BaslerCamera.py <- python code to interact with a Basler camera
|-- BaslerCameraAdapter.Dockerfile <- Dockerfile for camera service
|-- BaslerCameraThread.py <- enables for continuous image acqusition by camera threading
|-- DataModels.py <- pydantic data models
|-- docker-compose.yml <- exemplatory docker-compose call
|-- LICENSE
|-- main.py <- fastAPI server to communicate with the Basler camera
|-- README.md
|-- requirements.txt <- pip requirements
|-- utils.py <- helper functions that provide the ability to configure the server
|-- utils_fastapi.py <- wrapper functions that provide a standardized interface for fastapi
The default values to interact with a camera are configurable at startup by the following environment variables:
Environment variable | data type | comment |
---|---|---|
PREFIX | string | prefix of the environment variables |
LOG_LEVEL | string | in ["DEBUG", "INFO", "WARNING", "ERROR", "FATAL"] |
SERIAL_NUMBER | integer | |
IP_ADDRESS | string | |
SUBNET_MASK | string | |
TRANSMISSION_TYPE | string | in ["Unicast", "Multicast", "Broadcast"] |
DESTINATION_IP_ADDRESS | string | |
DESTINATION_PORT | integer | in [0, 653535] |
CONVERT_TO_FORMAT | string | in ["RGB", "BGR", "Mono", "null"] |
PIXEL_TYPE | string | see https://docs.baslerweb.com/pylonapi/net/T_Basler_Pylon_PixelType |
ACQUISITION_MODE | string | in ["SingleFrame", "Continuous"] |
EXPOSURE_TIME | integer | > 500; in micro seconds |
TIMEOUT | integer | > 200; in milli seconds |
EMULATE_CAMERA | bool | |
IMAGE_FORMAT | string | |
IMAGE_QUALITY | integer | in [10, 100]; in percent |
IMAGE_ROTATION_ANGLE | float | |
IMAGE_ROTATION_EXPAND | bool | |
FRAMES_PER_SECOND | integer | for continuous acquisition only |
Note: The configuration is done once when loading the data models (the module DataModels.py), i.e. at startup of the uvicorn server.
The default entrypoint (/
) provides basic information but rather just assures that the server is up.
See docs (endpoint /docs
) for details. This endpoint is the charm of FastAPI.
The documentation is automatically created with Swagger and provides and overview of all available endpoints as well as the ability to try them out with a convenient interface.
python ./main.py
or use uvicorn directly (always assuming that all package requirements.txt are installed)
uvicorn main:app --host=0.0.0.0 --port=5051
Use a virtualization engine like docker or podman:
docker build --tag=camera-adapter -f BaslerCameraAdapter.Dockerfile .
or the corresponding compose plugins on the example file (docker-compose.yml):
docker compose up -d
See example file for configuration options via environment variables.
This project is no official project of Basler. It relies on the official pypylon package which is available under the BSD 3-Clause License.
- max-scw
active