Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Provides a Python-based web-server to connect to a Basler camera (using PyPylon)

License

Notifications You must be signed in to change notification settings

max-scw/BaslerCameraAdapter

Repository files navigation

BaslerCameraAdapter

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/r/maxscw/basler-camera-adapter. The project also provides a frontend based on Python's streamlit (images are not published at docker hub.)

Structure

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 (api)
|-- BaslerCameraThread.py <- enables for continuous image acqusition by camera threading
|-- DataModels.py <- pydantic data models
|-- Frontend.Dockerfile <- Dockerfile for frontend
|-- LICENSE
|-- README.md
|-- app.py <- streamlit server for the frontend
|-- docker-compose.yml <- exemplatory docker-compose call
|-- main.py <- fastAPI server to communicate with the Basler camera
|-- requirements.txt <- pip requirements for api
|-- requirements_frontend.txt <- pip requirements for frontend
|-- utils.py <- helper functions that provide the ability to configure the server
|-- utils_fastapi.py <- wrapper functions that provide a standardized interface for fastapi

Configuration

The default values to interact with a camera are configurable at startup by the following environment variables:

Environment variable data type comment
ACQUISITION_MODE string in ["SingleFrame", "Continuous"]
CONVERT_TO_FORMAT string in ["RGB", "BGR", "Mono", "null"]
DESTINATION_IP_ADDRESS string
DESTINATION_PORT integer in [0, 653535]
EXPOSURE_TIME integer > 500; in micro seconds
FASTAPI_ROOT_PATH string
FRAMES_PER_SECOND integer for continuous acquisition only
IMAGE_FORMAT string
IMAGE_QUALITY integer in [10, 100]; in percent
IMAGE_ROI_LEFT integer / flot region of interest, left bound. In pixels or image fraction
IMAGE_ROI_TOP integer / float region of interest, upper bound. In pixels or image fraction
IMAGE_ROI_RIGHT integer / float region of interest, right bound. In pixels or image fraction
IMAGE_ROI_BOTTOM integer / float region of interest, lower bound. In pixels or image fraction
IMAGE_ROTATION_ANGLE float
IMAGE_ROTATION_EXPAND bool
IP_ADDRESS string
LOG_LEVEL string in ["DEBUG", "INFO", "WARNING", "ERROR", "FATAL"]
PIXEL_TYPE string see https://docs.baslerweb.com/pylonapi/net/T_Basler_Pylon_PixelType
PREFIX string prefix of the environment variables
SERIAL_NUMBER integer
SSL_CERTIFICATE string
SSL_KEYFILE string
SUBNET_MASK string
TEST_IMAGE string Path to image(s) that should be returned for emulated cameras
TIMEOUT_MS integer > 200; in milli seconds
TRANSMISSION_TYPE string in ["Unicast", "Multicast", "Broadcast"]

Note: The configuration is done once when loading the data models (the module DataModels.py), i.e. at startup of the uvicorn server.

Usage

The default entrypoint (/) provides basic information but rather just assures that the server is up.

BaslerCameraAdapter_DefaultEntrypoint.jpg

See docs (endpoint /docs) for details. This endpoint is the charm of FastAPI.

BaslerCameraAdapter_docs.jpg

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.

BaslerCameraAdapter_docs_take_photo.jpg

The frontend provides a nicer interface organizing the settings of the api in groups and offers the functionality to save images.

BaslerCameraAdapter_Frontend1.jpg

Installation

Python

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

For the frontend it is

streamlit run ./app.py

Docker

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

The docker-compose file starts the frontend, too. See example file for configuration options via environment variables.

Acknowledgments / Disclaimer

This project is no official project of Basler. It relies on the official pypylon package which is available under the BSD 3-Clause License.

Author

  • max-scw

Status

active

About

Provides a Python-based web-server to connect to a Basler camera (using PyPylon)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

AltStyle によって変換されたページ (->オリジナル) /