diff --git a/filter/filters_circleci.go b/filter/filters_circleci.go index aaca83f6..eba06743 100644 --- a/filter/filters_circleci.go +++ b/filter/filters_circleci.go @@ -31,13 +31,13 @@ import ( "io" ) -// NewMOGFilter 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 { +// NewMOG returns a pointer to a new NoOp struct for testing purposes only. +func NewMOG(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *NoOp { return &NoOp{dst: dst} } -// NewKNNFilter 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 { +// NewKNN returns a pointer to a new NoOp struct for testing purposes only. +func NewKNN(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *NoOp { return &NoOp{dst: dst} } diff --git a/filter/knn.go b/filter/knn.go index cc5a8a37..b9b1c3f5 100644 --- a/filter/knn.go +++ b/filter/knn.go @@ -37,9 +37,9 @@ import ( "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. -type KNNFilter struct { +type KNN struct { dst io.WriteCloser // Destination to which motion containing frames go. 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. @@ -51,21 +51,21 @@ type KNNFilter struct { hfCount int // Counter for the hold array. } -// NewKNNFilter returns a pointer to a new KNNFilter. -func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *KNNFilter { +// NewKNN returns a pointer to a new KNN filter struct. +func NewKNN(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *KNN { bs := gocv.NewBackgroundSubtractorKNNWithParams(history, threshold, false) k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(kernelSize, kernelSize)) var windows []*gocv.Window if debug { 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. // Close frees resources used by gocv, because it has to be done manually, due to // it using c-go. -func (m *KNNFilter) Close() error { +func (m *KNN) Close() error { m.bs.Close() m.knl.Close() for _, window := range m.windows { @@ -77,7 +77,7 @@ func (m *KNNFilter) 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 (m *KNNFilter) Write(f []byte) (int, error) { +func (m *KNN) Write(f []byte) (int, error) { if m.hfCount < (m.hf - 1) { m.hold[m.hfCount] = f m.hfCount++ diff --git a/filter/mog.go b/filter/mog.go index 20fd5807..80706ecf 100644 --- a/filter/mog.go +++ b/filter/mog.go @@ -37,9 +37,9 @@ import ( "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. -type MOGFilter struct { +type MOG struct { dst io.WriteCloser // Destination to which motion containing frames go. 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. @@ -51,21 +51,21 @@ type MOGFilter struct { hfCount int // Counter for the hold array. } -// NewMOGFilter returns a pointer to a new MOGFilter struct. -func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *MOGFilter { +// NewMOG returns a pointer to a new MOG filter struct. +func NewMOG(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *MOG { bs := gocv.NewBackgroundSubtractorMOG2WithParams(history, threshold, false) k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(3, 3)) var windows []*gocv.Window if debug { 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. // Close frees resources used by gocv, because it has to be done manually, due to // it using c-go. -func (m *MOGFilter) Close() error { +func (m *MOG) Close() error { m.bs.Close() m.knl.Close() for _, window := range m.windows { @@ -77,7 +77,7 @@ func (m *MOGFilter) 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 (m *MOGFilter) Write(f []byte) (int, error) { +func (m *MOG) Write(f []byte) (int, error) { if m.hfCount < (m.hf - 1) { m.hold[m.hfCount] = f m.hfCount++ diff --git a/filter/vfps.go b/filter/vfps.go index 93b6f543..9a9b9a4e 100644 --- a/filter/vfps.go +++ b/filter/vfps.go @@ -30,27 +30,27 @@ import ( "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 // sends frames at a reduced framerate. -type VariableFPSFilter struct { +type VariableFPS struct { filter Filter dst io.WriteCloser frames uint count uint } -// NewVariableFPSFilter returns a pointer to a new VariableFPSFilter struct. -func NewVariableFPSFilter(dst io.WriteCloser, minFPS float64, filter Filter) *VariableFPSFilter { +// NewVariableFPS returns a pointer to a new VariableFPS filter struct. +func NewVariableFPS(dst io.WriteCloser, minFPS float64, filter Filter) *VariableFPS { frames := uint(25 / minFPS) - return &VariableFPSFilter{filter, dst, frames, 0} + return &VariableFPS{filter, dst, frames, 0} } // Implements io.Writer. // 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 // 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 if v.count == 0 { @@ -62,6 +62,6 @@ func (v *VariableFPSFilter) Write(f []byte) (int, error) { // Implements io.Closer. // Close calls the motion filter's Close method. -func (v *VariableFPSFilter) Close() error { +func (v *VariableFPS) Close() error { return v.filter.Close() } diff --git a/revid/revid.go b/revid/revid.go index 5af91f73..5dd4a778 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -341,11 +341,11 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.FilterNoOp: r.filters[i] = filter.NewNoOp(dst) 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: - 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: - 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: r.filters[i] = filter.NewDifference(dst, r.cfg.ShowWindows, r.cfg.DiffThreshold) default: