mirror of https://bitbucket.org/ausocean/av.git
commenting and refinement
This commit is contained in:
parent
b588321d00
commit
b597fb9a1a
|
@ -40,15 +40,15 @@ import (
|
|||
// MOGFilter is a filter that provides basic motion detection. MoG is short for
|
||||
// Mixture of Gaussians method.
|
||||
type MOGFilter struct {
|
||||
dst io.WriteCloser
|
||||
area float64
|
||||
bs *gocv.BackgroundSubtractorMOG2
|
||||
knl gocv.Mat
|
||||
debug bool
|
||||
windows []*gocv.Window
|
||||
hold [][]byte
|
||||
hf int
|
||||
hfCount int
|
||||
dst io.WriteCloser //writer and closer interface
|
||||
area float64 //minimum area that motion
|
||||
bs *gocv.BackgroundSubtractorMOG2 //Uses the MOG algorithm to find the difference between the current and background frame
|
||||
knl gocv.Mat //matrix that is used for calculations
|
||||
debug bool //if true then debug windows with the bounding boxes and difference will be shown on the screen
|
||||
windows []*gocv.Window //holds debug windows
|
||||
hold [][]byte //will hold all frames up to hf (so only every hf frame is motion detected)
|
||||
hf int //the number of frames to be held
|
||||
hfCount int //counter for the hold array
|
||||
}
|
||||
|
||||
// NewMOGFilter returns a pointer to a new MOGFilter struct.
|
||||
|
@ -59,8 +59,7 @@ func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debu
|
|||
if debug {
|
||||
windows = []*gocv.Window{gocv.NewWindow("MOG: Bounding boxes"), gocv.NewWindow("MOG: Motion")}
|
||||
}
|
||||
hold := make([][]byte, hf-1)
|
||||
return &MOGFilter{dst, area, &bs, k, debug, windows, hold, hf, 0}
|
||||
return &MOGFilter{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0}
|
||||
}
|
||||
|
||||
// Implements io.Closer.
|
||||
|
@ -82,7 +81,7 @@ func (m *MOGFilter) Write(f []byte) (int, error) {
|
|||
if m.hfCount < (m.hf - 1) {
|
||||
m.hold[m.hfCount] = f
|
||||
m.hfCount++
|
||||
return 0, nil
|
||||
return len(f), nil
|
||||
}
|
||||
|
||||
m.hfCount = 0
|
||||
|
|
Loading…
Reference in New Issue