Custom Pipelines
An intro to writing custom pipelines
While Synapse includes several built-in pipelines to get started quickly, its real power lies in its extensibility. Users can define their own custom pipelines and write code that runs directly within the runtime. This allows full control over the vision processing flow—enabling specialized logic, custom models, and unique integrations that go beyond the defaults.
In this section, we’ll walk through how to create and register your own pipeline, define processing steps, and take advantage of Synapse's runtime to execute custom logic efficiently, using a simple pipeline example that will draw a circle on the screen using OpenCV code.
Defining the pipeline class
In order to write a custom pipeline, we need to create a python file inside of the project folder.
Any file with the name convention *_pipeline.py (e.g apriltag_pipeline.py) will automatically be recognized as a file that might have a pipeline defined inside it.
Inside of the file, we can define a class that extends the base Pipeline class from the Synapse library:
from synapse import Pipeline, PipelineSettings
from synapse.core.pipeline import FrameResult
class MyPipeline(Pipeline):
def __init__(self, settings: PipelineSettings):
super().__init__(settings)
def processFrame(self, img: Frame, timestamp: float) -> Frame:
# Process loop for the pipeline, will be called every frame
# with the image from the camera.
# Here we can run any opencv-like code we would like.
return imgThis class will automatically be recognized as a valid pipeline type and will be accessable via the UI without any changes.
The super().__init__(settings)call is required in order for the pipeline to function correctly
Defining Pipeline Settings
In order for our pipeline to have configurable settings, we will need to define a settings class, which will extend from the PipelineSettings class, and will be automatically validated with in-code constraints:
Now, these settings will be accessable via the UI and be validated automatically to match the constraint we gave it in-code.
Putting it all together
Now, we can add some OpenCV code that will draw a circle on the screen for us, based on the settings we provide it in the UI:
This pipeline will automatically become a valid and validated pipeline within the UI & NetworkTables without any modifications to it.
Pipeline Results
Coming soon...
Last updated