mirror of https://bitbucket.org/ausocean/av.git
filter: change names so that they don't have filter in them
This commit is contained in:
parent
0dfb2df939
commit
02777c4dd5
|
@ -32,12 +32,12 @@ import (
|
|||
)
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
func NewKNN(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *NoOp {
|
||||
return &NoOp{dst: dst}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import (
|
|||
|
||||
// KNNFilter 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.
|
||||
|
@ -52,20 +52,20 @@ type KNNFilter struct {
|
|||
}
|
||||
|
||||
// NewKNNFilter returns a pointer to a new KNNFilter.
|
||||
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)
|
||||
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++
|
||||
|
|
|
@ -39,7 +39,7 @@ import (
|
|||
|
||||
// MOGFilter 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.
|
||||
|
@ -52,20 +52,20 @@ type MOGFilter struct {
|
|||
}
|
||||
|
||||
// NewMOGFilter returns a pointer to a new MOGFilter 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)
|
||||
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++
|
||||
|
|
|
@ -33,7 +33,7 @@ import (
|
|||
// VariableFPSFilter 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
|
||||
|
@ -41,16 +41,16 @@ type VariableFPSFilter struct {
|
|||
}
|
||||
|
||||
// NewVariableFPSFilter returns a pointer to a new VariableFPSFilter 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)
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue