DEV Community

Cover image for The Hot-Reload Magic - Tweak Pipelines Live (No Restarts!)
Elliot Silver
Elliot Silver

Posted on

The Hot-Reload Magic - Tweak Pipelines Live (No Restarts!)

Edit your config.toml while the app is running and watch the pipeline update instantly. No recompiling. No stopping the camera. Pure iteration bliss.

Why This Matters

If you've ever prototyped with raw GoCV (or any OpenCV binding), you know the pain:

  • Change a threshold or kernel size? Edit code → recompile → restart → wait for camera init.
  • Takes 10-30 seconds per tweak → kills your flow.
  • Accidentally leak a Mat? Crash and start over.

GoCVKit fixes this with live config hot-reload. Save config.toml → the running app detects the change → rebuilds the entire pipeline on the fly → you see the result immediately.

It's the closest thing Go has to Jupyter notebooks for computer vision.

How It Works (The Magic Explained)

Under the hood it's simple and robust:

  1. A lightweight file watcher (using fsnotify) monitors config.toml.
  2. On any save, the config is re-parsed.
  3. The pipeline builder recreates all processors with new parameters.
  4. The next frame uses the brand-new pipeline – no frames dropped, no allocations outside the double buffer.

Zero boilerplate for you. Zero leaks guaranteed.

Hands-On: See It Yourself

Fire up the quick start if you haven't already:

mkdir gocvkit-demo && cd gocvkit-demo
go mod init demo
go get github.com/Elliot727/gocvkit
Enter fullscreen mode Exit fullscreen mode

main.go

package main

import (
    "log"
    "github.com/Elliot727/gocvkit"
)

func main() {
    app, err := gocvkit.NewApp("config.toml")
    if err != nil {
        log.Fatal(err)
    }
    defer app.Close()
    app.Run(nil)
}
Enter fullscreen mode Exit fullscreen mode

Create initial config

config.toml

[app]
window_name = "GoCVKit – Hot-Reload Demo"

[[pipeline.steps]]
name = "Grayscale"

[[pipeline.steps]]
name = "Canny"
low = 50
high = 150
Enter fullscreen mode Exit fullscreen mode

Now the fun part:

  1. Window opens showing live Canny edges.
  2. Open config.toml in your editor.
  3. Change high = 150high = 300 → save. → Edges instantly thicken.
  4. Replace the entire Canny block with GaussianBlur:
[[pipeline.steps]]
name = "GaussianBlur"
kernel = 15
sigma = 3
Enter fullscreen mode Exit fullscreen mode

Save → blur appears instantly.

  1. Try something wild:
[[pipeline.steps]]
name = "Grayscale"

[[pipeline.steps]]
name = "MedianBlur"
k = 21
Enter fullscreen mode Exit fullscreen mode

No restarts. No code changes. Just pure experimentation.

Pro Tips for Hot-Reload Happiness

  • Typos? GoCVKit prints clear errors in the terminal but keeps the old pipeline running – no crash.
  • Add/remove steps freely – the builder handles it gracefully.
  • Want to test recording too? Flip record = true live and it starts/stops without hassle.

The pipeline itself uses double-buffering so frame processing never blocks or allocates per frame. That's why you get smooth FPS even during reloads.

Try It Yourself

Grab the repo, run the example above, and go wild with the config. Break it on purpose – you'll see how forgiving it is.

What's the first parameter you always tweak in edge detection? Thresholds? Kernel sizes? Tell me in the comments!

Top comments (0)