commenting and refinement

This commit is contained in:
Ella Pietraroia 2020-01-22 14:53:03 +10:30
parent b588321d00
commit b597fb9a1a
1 changed files with 11 additions and 12 deletions

View File

@ -40,15 +40,15 @@ import (
// MOGFilter is a filter that provides basic motion detection. MoG is short for // MOGFilter is a filter that provides basic motion detection. MoG is short for
// Mixture of Gaussians method. // Mixture of Gaussians method.
type MOGFilter struct { type MOGFilter struct {
dst io.WriteCloser dst io.WriteCloser //writer and closer interface
area float64 area float64 //minimum area that motion
bs *gocv.BackgroundSubtractorMOG2 bs *gocv.BackgroundSubtractorMOG2 //Uses the MOG algorithm to find the difference between the current and background frame
knl gocv.Mat knl gocv.Mat //matrix that is used for calculations
debug bool debug bool //if true then debug windows with the bounding boxes and difference will be shown on the screen
windows []*gocv.Window windows []*gocv.Window //holds debug windows
hold [][]byte hold [][]byte //will hold all frames up to hf (so only every hf frame is motion detected)
hf int hf int //the number of frames to be held
hfCount int hfCount int //counter for the hold array
} }
// NewMOGFilter returns a pointer to a new MOGFilter struct. // 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 { 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")}
} }
hold := make([][]byte, hf-1) return &MOGFilter{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0}
return &MOGFilter{dst, area, &bs, k, debug, windows, hold, hf, 0}
} }
// Implements io.Closer. // Implements io.Closer.
@ -82,7 +81,7 @@ func (m *MOGFilter) 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++
return 0, nil return len(f), nil
} }
m.hfCount = 0 m.hfCount = 0