mirror of https://bitbucket.org/ausocean/av.git
filter: DiffFilter → Difference
This commit is contained in:
parent
458933babb
commit
e0fa474906
|
@ -38,10 +38,10 @@ import (
|
|||
"gocv.io/x/gocv"
|
||||
)
|
||||
|
||||
// DiffFilter is a filter that provides basic motion detection. DiffFilter calculates
|
||||
// Difference is a filter that provides basic motion detection. Difference calculates
|
||||
// the absolute difference for each pixel between two frames, then finds the mean. If
|
||||
// the mean is above a given threshold, then it is considered motion.
|
||||
type DiffFilter struct {
|
||||
type Difference struct {
|
||||
dst io.WriteCloser
|
||||
thresh float64
|
||||
prev gocv.Mat
|
||||
|
@ -49,19 +49,19 @@ type DiffFilter struct {
|
|||
windows []*gocv.Window
|
||||
}
|
||||
|
||||
// NewDiffFilter returns a pointer to a new DiffFilter.
|
||||
func NewDiffFilter(dst io.WriteCloser, debug bool, threshold float64) *DiffFilter {
|
||||
// NewDifference returns a pointer to a new Difference struct.
|
||||
func NewDifference(dst io.WriteCloser, debug bool, threshold float64) *Difference {
|
||||
var windows []*gocv.Window
|
||||
if debug {
|
||||
windows = []*gocv.Window{gocv.NewWindow("Diff: Bounding boxes"), gocv.NewWindow("Diff: Motion")}
|
||||
}
|
||||
return &DiffFilter{dst, threshold, gocv.NewMat(), debug, windows}
|
||||
return &Difference{dst, threshold, gocv.NewMat(), debug, windows}
|
||||
}
|
||||
|
||||
// Implements io.Closer.
|
||||
// Close frees resources used by gocv, because it has to be done manually, due to
|
||||
// it using c-go.
|
||||
func (d *DiffFilter) Close() error {
|
||||
func (d *Difference) Close() error {
|
||||
d.prev.Close()
|
||||
for _, window := range d.windows {
|
||||
window.Close()
|
||||
|
@ -72,7 +72,7 @@ func (d *DiffFilter) Close() error {
|
|||
// Implements io.Writer.
|
||||
// Write applies the motion filter to the video stream. Only frames with motion
|
||||
// are written to the destination encoder, frames without are discarded.
|
||||
func (d *DiffFilter) Write(f []byte) (int, error) {
|
||||
func (d *Difference) Write(f []byte) (int, error) {
|
||||
if d.prev.Empty() {
|
||||
d.prev, _ = gocv.IMDecode(f, gocv.IMReadColor)
|
||||
return 0, nil
|
||||
|
|
|
@ -41,7 +41,7 @@ func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSi
|
|||
return &NoOp{dst: dst}
|
||||
}
|
||||
|
||||
// NewDiffFilter returns a pointer to a new NoOp struct for testing purposes only.
|
||||
func NewDiffFilter(dst io.WriteCloser, debug bool, threshold float64) *NoOp {
|
||||
// NewDiffference returns a pointer to a new NoOp struct for testing purposes only.
|
||||
func NewDifference(dst io.WriteCloser, debug bool, threshold float64) *NoOp {
|
||||
return &NoOp{dst: dst}
|
||||
}
|
||||
|
|
|
@ -343,7 +343,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
|||
case config.FilterKNN:
|
||||
r.filters[i] = filter.NewKNNFilter(dst, r.cfg.KNNMinArea, r.cfg.KNNThreshold, int(r.cfg.KNNHistory), int(r.cfg.KNNKernel), r.cfg.ShowWindows, r.cfg.MotionInterval)
|
||||
case config.FilterDifference:
|
||||
r.filters[i] = filter.NewDiffFilter(dst, r.cfg.ShowWindows, r.cfg.DiffThreshold)
|
||||
r.filters[i] = filter.NewDifference(dst, r.cfg.ShowWindows, r.cfg.DiffThreshold)
|
||||
default:
|
||||
panic("Undefined Filter")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue