From 6f16f68611e6732303009f23a08f6650ac39f640 Mon Sep 17 00:00:00 2001 From: Ella Pietraroia Date: Thu, 2 Jan 2020 14:45:59 +1030 Subject: [PATCH] adding variable to choose how many frames to skip before filtering --- filter/mog.go | 4 ++-- revid/config/config.go | 8 ++++++++ revid/revid.go | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/filter/mog.go b/filter/mog.go index 5a2bb7ad..cff19d3e 100644 --- a/filter/mog.go +++ b/filter/mog.go @@ -139,8 +139,9 @@ func (m *MOGFilter) Write(f []byte) (int, error) { } // Write to destination, past 4 frames then current frame. - for _, h := range m.hold { + for i, h := range m.hold { _, err := m.dst.Write(h) + m.hold[i] = nil if err != nil { return 0, err } @@ -149,5 +150,4 @@ func (m *MOGFilter) Write(f []byte) (int, error) { hfCount = 0 return m.dst.Write(f) } - } diff --git a/revid/config/config.go b/revid/config/config.go index b37fc759..ea1f3b16 100644 --- a/revid/config/config.go +++ b/revid/config/config.go @@ -273,11 +273,19 @@ type Config struct { Width uint // Width defines the input video width Raspivid input. Bitrate uint // Bitrate specifies the bitrate for constant bitrate in kbps. +<<<<<<< HEAD HorizontalFlip bool // HorizontalFlip flips video horizontally for Raspivid input. VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input. Filters []int // Defines the methods of filtering to be used in between lexing and encoding. FilterFrames int // Sets the number of frames that are held before the filter is used (on the nth frame) PSITime int // Sets the time between a packet being sent. +======= + HorizontalFlip bool // HorizontalFlip flips video horizontally for Raspivid input. + VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input. + Filter int // Defines the method of filtering to be used in between lexing and encoding. + FilterFrames int // Sets the number of frames that are held before the filter is used (on the nth frame) + PSITime int // Sets the time between a packet being sent +>>>>>>> d097308e... adding variable to choose how many frames to skip before filtering // Ring buffer parameters. RBMaxElements int // The maximum possible number of elements in ring buffer. diff --git a/revid/revid.go b/revid/revid.go index f5398c72..a375847e 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -344,6 +344,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. r.encoders = multiWriter(encoders...) +<<<<<<< HEAD l := len(r.cfg.Filters) r.filters = []filter.Filter{filter.NewNoOp(r.encoders)} if l != 0 { @@ -365,6 +366,20 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. } dst = r.filters[i] } +======= + switch r.cfg.Filter { + case config.FilterNoOp: + r.filter = filter.NewNoOp(r.encoders) + case config.FilterMOG: + r.filter = filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, r.cfg.ShowWindows, r.cfg.FilterFrames) + case config.FilterVariableFPS: + r.filter = filter.NewVariableFPSFilter(r.encoders, minFPS, filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, r.cfg.ShowWindows, r.cfg.FilterFrames)) + case config.FilterKNN: + r.filter = filter.NewKNNFilter(r.encoders, knnMinArea, knnThreshold, knnHistory, knnKernel, r.cfg.ShowWindows) + + default: + panic("Undefined Filter") +>>>>>>> d097308e... adding variable to choose how many frames to skip before filtering } switch r.cfg.Input { @@ -694,6 +709,16 @@ func (r *Revid) Update(vars map[string]string) error { r.cfg.Logger.Log(logger.Warning, pkg+"invalid FilterFrames var", "value", value) break } +<<<<<<< HEAD +======= + r.cfg.Filter = v + case "FilterFrames": + v, err := strconv.Atoi(value) + if err != nil || v < 0 { + r.cfg.Logger.Log(logger.Warning, pkg+"invalid FilterFrames var", "value", value) + break + } +>>>>>>> d097308e... adding variable to choose how many frames to skip before filtering r.cfg.FilterFrames = v case "PSITime": v, err := strconv.Atoi(value)