Your First Real Project – Live Edge Detection with Recording
Source: Dev.to

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
Project setup
# If not done yet
mkdir gocvkit-edge && cd gocvkit-edge
go mod init edge-demo
go get github.com/Elliot727/gocvkit
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)
}
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
Run the app
go run .
You should see a live edge‑detection window with:
- Clean Canny edges
- Press
fto toggle FPS overlay - Recording started automatically (
edge_detection.mp4) - Edit any value in
config.toml→ save → instant update (thanks Week #2!)
Level It Up
Crank the blur for smoother edges
kernel = 15
sigma = 3
Softer edges
low = 30
high = 100
Add morphology to clean up noise
[[pipeline.steps]]
name = "Dilate"
kernel = 3
iterations = 1
Toggle recording live
Flip record = false in config.toml and save.
Bonus: Add a Simple Overlay with Frame Callback
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)
})
(Recompile once – but now you can hot‑reload the text by changing the string or making it config‑driven later.)
Pro Tips
- Recording auto‑rotates files if they get too big – no manual management.
- Press
Escorqto 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.toml above, run the program, and start playing. Break it. Fix it live. Feel the speed.
What’s your favorite edge‑detection tweak? Strong/thin lines or softer outlines? Drop it in the comments!