Merged in filter-names (pull request #368)

filter: change names so that they don't have filter in them

Approved-by: Scott Barnard <scott@ausocean.org>
Approved-by: Trek Hopton <trek.hopton@gmail.com>
This commit is contained in:
Ella Pietraroia 2020-02-03 06:26:41 +00:00
commit 5c9ffd6c1f
5 changed files with 28 additions and 28 deletions

View File

@ -31,13 +31,13 @@ import (
"io" "io"
) )
// NewMOGFilter returns a pointer to a new NoOp struct for testing purposes only. // NewMOG returns a pointer to a new NoOp struct for testing purposes only.
func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *NoOp { func NewMOG(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *NoOp {
return &NoOp{dst: dst} return &NoOp{dst: dst}
} }
// NewKNNFilter returns a pointer to a new NoOp struct for testing purposes only. // NewKNN returns a pointer to a new NoOp struct for testing purposes only.
func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *NoOp { func NewKNN(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *NoOp {
return &NoOp{dst: dst} return &NoOp{dst: dst}
} }

View File

@ -37,9 +37,9 @@ import (
"gocv.io/x/gocv" "gocv.io/x/gocv"
) )
// KNNFilter is a filter that provides basic motion detection. KNN is short for // KNN is a filter that provides basic motion detection. KNN is short for
// K-Nearest Neighbours method. // K-Nearest Neighbours method.
type KNNFilter struct { type KNN struct {
dst io.WriteCloser // Destination to which motion containing frames go. dst io.WriteCloser // Destination to which motion containing frames go.
area float64 // The minimum area that a contour can be found in. area float64 // The minimum area that a contour can be found in.
bs *gocv.BackgroundSubtractorKNN // Uses the KNN algorithm to find the difference between the current and background frame. bs *gocv.BackgroundSubtractorKNN // Uses the KNN algorithm to find the difference between the current and background frame.
@ -51,21 +51,21 @@ type KNNFilter struct {
hfCount int // Counter for the hold array. hfCount int // Counter for the hold array.
} }
// NewKNNFilter returns a pointer to a new KNNFilter. // NewKNN returns a pointer to a new KNN filter struct.
func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *KNNFilter { func NewKNN(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *KNN {
bs := gocv.NewBackgroundSubtractorKNNWithParams(history, threshold, false) bs := gocv.NewBackgroundSubtractorKNNWithParams(history, threshold, false)
k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(kernelSize, kernelSize)) k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(kernelSize, kernelSize))
var windows []*gocv.Window var windows []*gocv.Window
if debug { if debug {
windows = []*gocv.Window{gocv.NewWindow("KNN: Bounding boxes"), gocv.NewWindow("KNN: Motion")} windows = []*gocv.Window{gocv.NewWindow("KNN: Bounding boxes"), gocv.NewWindow("KNN: Motion")}
} }
return &KNNFilter{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0} return &KNN{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0}
} }
// Implements io.Closer. // Implements io.Closer.
// Close frees resources used by gocv, because it has to be done manually, due to // Close frees resources used by gocv, because it has to be done manually, due to
// it using c-go. // it using c-go.
func (m *KNNFilter) Close() error { func (m *KNN) Close() error {
m.bs.Close() m.bs.Close()
m.knl.Close() m.knl.Close()
for _, window := range m.windows { for _, window := range m.windows {
@ -77,7 +77,7 @@ func (m *KNNFilter) Close() error {
// Implements io.Writer. // Implements io.Writer.
// Write applies the motion filter to the video stream. Only frames with motion // Write applies the motion filter to the video stream. Only frames with motion
// are written to the destination encoder, frames without are discarded. // are written to the destination encoder, frames without are discarded.
func (m *KNNFilter) Write(f []byte) (int, error) { func (m *KNN) Write(f []byte) (int, error) {
if m.hfCount < (m.hf - 1) { if m.hfCount < (m.hf - 1) {
m.hold[m.hfCount] = f m.hold[m.hfCount] = f
m.hfCount++ m.hfCount++

View File

@ -37,9 +37,9 @@ import (
"gocv.io/x/gocv" "gocv.io/x/gocv"
) )
// MOGFilter is a filter that provides basic motion detection. MoG is short for // MOG is a filter that provides basic motion detection. MoG is short for
// Mixture of Gaussians method. // Mixture of Gaussians method.
type MOGFilter struct { type MOG struct {
dst io.WriteCloser // Destination to which motion containing frames go. dst io.WriteCloser // Destination to which motion containing frames go.
area float64 // The minimum area that a contour can be found in. area float64 // The minimum area that a contour can be found in.
bs *gocv.BackgroundSubtractorMOG2 // Uses the MOG algorithm to find the difference between the current and background frame. bs *gocv.BackgroundSubtractorMOG2 // Uses the MOG algorithm to find the difference between the current and background frame.
@ -51,21 +51,21 @@ type MOGFilter struct {
hfCount int // Counter for the hold array. hfCount int // Counter for the hold array.
} }
// NewMOGFilter returns a pointer to a new MOGFilter struct. // NewMOG returns a pointer to a new MOG filter struct.
func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *MOGFilter { func NewMOG(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *MOG {
bs := gocv.NewBackgroundSubtractorMOG2WithParams(history, threshold, false) bs := gocv.NewBackgroundSubtractorMOG2WithParams(history, threshold, false)
k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(3, 3)) k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(3, 3))
var windows []*gocv.Window var windows []*gocv.Window
if debug { if debug {
windows = []*gocv.Window{gocv.NewWindow("MOG: Bounding boxes"), gocv.NewWindow("MOG: Motion")} windows = []*gocv.Window{gocv.NewWindow("MOG: Bounding boxes"), gocv.NewWindow("MOG: Motion")}
} }
return &MOGFilter{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0} return &MOG{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0}
} }
// Implements io.Closer. // Implements io.Closer.
// Close frees resources used by gocv, because it has to be done manually, due to // Close frees resources used by gocv, because it has to be done manually, due to
// it using c-go. // it using c-go.
func (m *MOGFilter) Close() error { func (m *MOG) Close() error {
m.bs.Close() m.bs.Close()
m.knl.Close() m.knl.Close()
for _, window := range m.windows { for _, window := range m.windows {
@ -77,7 +77,7 @@ func (m *MOGFilter) Close() error {
// Implements io.Writer. // Implements io.Writer.
// Write applies the motion filter to the video stream. Only frames with motion // Write applies the motion filter to the video stream. Only frames with motion
// are written to the destination encoder, frames without are discarded. // are written to the destination encoder, frames without are discarded.
func (m *MOGFilter) Write(f []byte) (int, error) { func (m *MOG) Write(f []byte) (int, error) {
if m.hfCount < (m.hf - 1) { if m.hfCount < (m.hf - 1) {
m.hold[m.hfCount] = f m.hold[m.hfCount] = f
m.hfCount++ m.hfCount++

View File

@ -30,27 +30,27 @@ import (
"io" "io"
) )
// VariableFPSFilter is a filter that has a variable frame rate. When motion is // VariableFPS is a filter that has a variable frame rate. When motion is
// detected, the filter sends all frames and when it is not, the filter // detected, the filter sends all frames and when it is not, the filter
// sends frames at a reduced framerate. // sends frames at a reduced framerate.
type VariableFPSFilter struct { type VariableFPS struct {
filter Filter filter Filter
dst io.WriteCloser dst io.WriteCloser
frames uint frames uint
count uint count uint
} }
// NewVariableFPSFilter returns a pointer to a new VariableFPSFilter struct. // NewVariableFPS returns a pointer to a new VariableFPS filter struct.
func NewVariableFPSFilter(dst io.WriteCloser, minFPS float64, filter Filter) *VariableFPSFilter { func NewVariableFPS(dst io.WriteCloser, minFPS float64, filter Filter) *VariableFPS {
frames := uint(25 / minFPS) frames := uint(25 / minFPS)
return &VariableFPSFilter{filter, dst, frames, 0} return &VariableFPS{filter, dst, frames, 0}
} }
// Implements io.Writer. // Implements io.Writer.
// Write applies the motion filter to the video stream. Frames are sent // Write applies the motion filter to the video stream. Frames are sent
// at a reduced frame rate, except when motion is detected, then all frames // at a reduced frame rate, except when motion is detected, then all frames
// with motion are sent. // with motion are sent.
func (v *VariableFPSFilter) Write(f []byte) (int, error) { func (v *VariableFPS) Write(f []byte) (int, error) {
v.count = (v.count + 1) % v.frames v.count = (v.count + 1) % v.frames
if v.count == 0 { if v.count == 0 {
@ -62,6 +62,6 @@ func (v *VariableFPSFilter) Write(f []byte) (int, error) {
// Implements io.Closer. // Implements io.Closer.
// Close calls the motion filter's Close method. // Close calls the motion filter's Close method.
func (v *VariableFPSFilter) Close() error { func (v *VariableFPS) Close() error {
return v.filter.Close() return v.filter.Close()
} }

View File

@ -341,11 +341,11 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
case config.FilterNoOp: case config.FilterNoOp:
r.filters[i] = filter.NewNoOp(dst) r.filters[i] = filter.NewNoOp(dst)
case config.FilterMOG: case config.FilterMOG:
r.filters[i] = filter.NewMOGFilter(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows, r.cfg.MotionInterval) r.filters[i] = filter.NewMOG(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows, r.cfg.MotionInterval)
case config.FilterVariableFPS: case config.FilterVariableFPS:
r.filters[i] = filter.NewVariableFPSFilter(dst, r.cfg.MinFPS, filter.NewMOGFilter(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows, r.cfg.MotionInterval)) r.filters[i] = filter.NewVariableFPS(dst, r.cfg.MinFPS, filter.NewMOG(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows, r.cfg.MotionInterval))
case config.FilterKNN: 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) r.filters[i] = filter.NewKNN(dst, r.cfg.KNNMinArea, r.cfg.KNNThreshold, int(r.cfg.KNNHistory), int(r.cfg.KNNKernel), r.cfg.ShowWindows, r.cfg.MotionInterval)
case config.FilterDifference: case config.FilterDifference:
r.filters[i] = filter.NewDifference(dst, r.cfg.ShowWindows, r.cfg.DiffThreshold) r.filters[i] = filter.NewDifference(dst, r.cfg.ShowWindows, r.cfg.DiffThreshold)
default: default: