av/filter/debug.go

71 lines
1.9 KiB
Go
Raw Normal View History

// +build debug
// +build !circleci
/*
DESCRIPTION
Displays debug information for the motion filters.
AUTHORS
Scott Barnard <scott@ausocean.org>
LICENSE
This file is Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
package filter
import (
"image"
"image/color"
"gocv.io/x/gocv"
)
// debugWindows is used for displaying debug information for the motion filters.
type debugWindows struct {
windows []*gocv.Window
}
// closeWindows frees resources used by gocv.
func (d *debugWindows) closeWindows() {
for _, window := range d.windows {
window.Close()
}
}
// newWindows creates debugging windows for the motion filter.
func (d *debugWindows) newWindows(name string) {
d.windows = []*gocv.Window{gocv.NewWindow(name + ": Bounding boxes"), gocv.NewWindow(name + ": Motion")}
}
// showDebug displays debug information for the motion filters.
func (d *debugWindows) showDebug(img, imgDelta gocv.Mat, motion bool, contours ...[][]image.Point) {
if len(contours) > 0 {
for _, c := range contours[0] {
rect := gocv.BoundingRect(c)
gocv.Rectangle(&img, rect, color.RGBA{0, 0, 255, 0}, 1)
}
}
if motion {
gocv.PutText(&img, "Motion", image.Pt(32, 32), gocv.FontHersheyPlain, 2.0, color.RGBA{255, 0, 0, 0}, 2)
}
d.windows[0].IMShow(img)
d.windows[1].IMShow(imgDelta)
d.windows[0].WaitKey(1)
}