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.

This is not a guide for how to write pipeline processing code, but how to implement a pipeline class. If you're looking to learn about writing vision algorithms, we recommend exploring the OpenCV Python Examples

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 img

This class will automatically be recognized as a valid pipeline type and will be accessable via the UI without any changes.

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.

For detailed information about the Settings API and the available constraint types, refer to the documentation here

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