DEV Community

Cover image for Your First Real Project – Live Edge Detection with Recording
Elliot Silver
Elliot Silver

Posted on

Your First Real Project – Live Edge Detection with Recording

Why This Matters

Edge detection is the "hello world" of serious computer vision – it's where you start tuning parameters, chasing clean lines, and realizing how much time raw OpenCV setups waste.

With vanilla GoCV you'd spend dozens of lines on:

  • Camera capture loop
  • Window creation
  • Mat management (and inevitable leaks)
  • Keyboard handling
  • Recording logic

GoCVKit gives you all that for free. You focus only on the pipeline.

Hands-On: Build the Edge Detector

Start from the quick start (if you followed Week #2, you already have this):

# If not done yet
mkdir gocvkit-edge && cd gocvkit-edge
go mod init edge-demo
go get github.com/Elliot727/gocvkit
Enter fullscreen mode Exit fullscreen mode
# main.go  same as always
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

Now create the star of the show – config.toml:

[app]
window_name = "GoCVKit – Live Edge Detection"
record = true                  # Save processed video automatically
output = "edge_detection.mp4"  # Optional: custom filename

[camera]
device_id = 0
# file = "demo.mp4"            # Uncomment to use a video file instead

[stream]
enabled = false                # Keep off for now – we can enable later

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

[[pipeline.steps]]
name = "GaussianBlur"
kernel = 9
sigma = 1.8

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

Run it:

go run .
Enter fullscreen mode Exit fullscreen mode

Boom – live edge detection window with:

  • Clean Canny edges
  • Press f to toggle FPS overlay
  • Recording started automatically (check your folder for edge_detection.mp4)
  • Edit any value in config.toml → save → instant update (thanks Week #2!)

Level It Up

Try these live tweaks (no restart needed):

  1. Crank the blur for smoother edges:
   kernel = 15
   sigma = 3
Enter fullscreen mode Exit fullscreen mode
  1. Softer edges:
   low = 30
   high = 100
Enter fullscreen mode Exit fullscreen mode
  1. Add morphology to clean up noise:
   [[pipeline.steps]]
   name = "Dilate"
   kernel = 3
   iterations = 1
Enter fullscreen mode Exit fullscreen mode
  1. Toggle recording on/off live by flipping record = false → save.

Bonus: Add a Simple Overlay with Frame Callback

Want to show current thresholds on screen? Add a tiny callback to main.go:

app.Run(func(frame *gocv.Mat) {
    // Runs on the final processed frame
    gocv.PutText(frame, "Low: 50  High: 150", image.Pt(10, 30),
        gocv.FontHersheyPlain, 1.5, gocv.NewScalar(255, 255, 255, 0), 2)
})
Enter fullscreen mode Exit fullscreen mode

(Recompile once – but now you can hot-reload the text by changing the string and saving config if you make it config-driven later.)

Pro Tips

  • Recording auto-rotates files if they get too big – no manual management.
  • Press Esc or q to quit gracefully (resources cleaned up).
  • Run out of webcam? Swap to a video file by uncommenting file = "demo.mp4".

Try It Yourself

Copy the config above, run it, and start playing. Break it. Fix it live. Feel the speed.

What's your favorite edge detection tweak? Do you prefer strong/thin lines or softer outlines? Drop it in the comments!

Top comments (0)