From 9d857b8a66f0dbdf66ee1379b4730a39a630b267 Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 31 Dec 2019 15:04:19 +1030 Subject: [PATCH 1/4] Created constants for the MOG filter --- filter/filters_circleci.go | 2 +- filter/mog.go | 4 ++-- revid/revid.go | 12 +++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/filter/filters_circleci.go b/filter/filters_circleci.go index e9fc155a..f6d46082 100644 --- a/filter/filters_circleci.go +++ b/filter/filters_circleci.go @@ -32,7 +32,7 @@ import ( ) // NewMOGFilter returns a pointer to a new NoOp struct for testing purposes only. -func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool) *NoOp { +func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool) *NoOp { return &NoOp{dst: dst} } diff --git a/filter/mog.go b/filter/mog.go index 283ea034..11bed5a6 100644 --- a/filter/mog.go +++ b/filter/mog.go @@ -48,9 +48,9 @@ type MOGFilter struct { } // NewMOGFilter returns a pointer to a new MOGFilter struct. -func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool) *MOGFilter { +func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool) *MOGFilter { bs := gocv.NewBackgroundSubtractorMOG2WithParams(history, threshold, false) - k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(kernelSize, kernelSize)) + k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(3, 3)) var windows []*gocv.Window if debug { windows = []*gocv.Window{gocv.NewWindow("Debug: Bounding boxes"), gocv.NewWindow("Debug: Motion")} diff --git a/revid/revid.go b/revid/revid.go index fd3f83cf..075034a1 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -76,13 +76,18 @@ const ( rtmpConnectionTimeout = 10 ) -// KNN filter properties +// Motion filter parameters const ( knnMinArea = 25.0 knnThreshold = 300 knnHistory = 300 knnKernel = 9 knnShowWindows = true + minArea = 25.0 + threshold = 20.0 + history = 500 + showWindows = true + minFPS = 1.0 ) const pkg = "revid: " @@ -341,11 +346,12 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.FilterNoOp: r.filter = filter.NewNoOp(r.encoders) case config.FilterMOG: - r.filter = filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true) + r.filter = filter.NewMOGFilter(r.encoders, minArea, threshold, history, showWindows) case config.FilterVariableFPS: - r.filter = filter.NewVariableFPSFilter(r.encoders, 1.0, filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true)) + r.filter = filter.NewVariableFPSFilter(r.encoders, minFPS, filter.NewMOGFilter(r.encoders, minArea, threshold, history, showWindows)) case config.FilterKNN: r.filter = filter.NewKNNFilter(r.encoders, knnMinArea, knnThreshold, knnHistory, knnKernel, knnShowWindows) + default: panic("Undefined Filter") } From c7fa55a993f5f94586899f06f75683dc26900732 Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 31 Dec 2019 15:41:54 +1030 Subject: [PATCH 2/4] revid/revid.go: Renamed constants to be more specific to the MOG filter --- revid/revid.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 075034a1..4def6f2c 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -78,16 +78,15 @@ const ( // Motion filter parameters const ( - knnMinArea = 25.0 - knnThreshold = 300 - knnHistory = 300 - knnKernel = 9 - knnShowWindows = true - minArea = 25.0 - threshold = 20.0 - history = 500 - showWindows = true - minFPS = 1.0 + knnMinArea = 25.0 + knnThreshold = 300 + knnHistory = 300 + knnKernel = 9 + mogMinArea = 25.0 + mogThreshold = 20.0 + mogHistory = 500 + showWindows = true + minFPS = 1.0 ) const pkg = "revid: " @@ -346,11 +345,11 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.FilterNoOp: r.filter = filter.NewNoOp(r.encoders) case config.FilterMOG: - r.filter = filter.NewMOGFilter(r.encoders, minArea, threshold, history, showWindows) + r.filter = filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, showWindows) case config.FilterVariableFPS: - r.filter = filter.NewVariableFPSFilter(r.encoders, minFPS, filter.NewMOGFilter(r.encoders, minArea, threshold, history, showWindows)) + r.filter = filter.NewVariableFPSFilter(r.encoders, minFPS, filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, showWindows)) case config.FilterKNN: - r.filter = filter.NewKNNFilter(r.encoders, knnMinArea, knnThreshold, knnHistory, knnKernel, knnShowWindows) + r.filter = filter.NewKNNFilter(r.encoders, knnMinArea, knnThreshold, knnHistory, knnKernel, showWindows) default: panic("Undefined Filter") From cf51d0753265f2f1a2adca5cf7f9bd168123b06b Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 2 Jan 2020 13:35:03 +1030 Subject: [PATCH 3/4] revid/revid.go: Separated const block into 3 sections --- revid/revid.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 4def6f2c..8f462f99 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -77,16 +77,24 @@ const ( ) // Motion filter parameters +const ( + showWindows = true + minFPS = 1.0 +) + +// KNN specific parameters const ( knnMinArea = 25.0 knnThreshold = 300 knnHistory = 300 knnKernel = 9 +) + +// MOG specific parameters +const ( mogMinArea = 25.0 mogThreshold = 20.0 mogHistory = 500 - showWindows = true - minFPS = 1.0 ) const pkg = "revid: " From 90f448170fbe511ebd32a127840d292519bb79a7 Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 2 Jan 2020 13:38:31 +1030 Subject: [PATCH 4/4] revid/revid.go: Full stops at the end of comments. --- revid/revid.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 8f462f99..cdbc1cc5 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -9,7 +9,7 @@ AUTHORS Trek Hopton LICENSE - revid is Copyright (C) 2017-2018 the Australian Ocean Lab (AusOcean) + revid is Copyright (C) 2017-2020 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the @@ -76,13 +76,13 @@ const ( rtmpConnectionTimeout = 10 ) -// Motion filter parameters +// Motion filter parameters. const ( showWindows = true minFPS = 1.0 ) -// KNN specific parameters +// KNN specific parameters. const ( knnMinArea = 25.0 knnThreshold = 300 @@ -90,7 +90,7 @@ const ( knnKernel = 9 ) -// MOG specific parameters +// MOG specific parameters. const ( mogMinArea = 25.0 mogThreshold = 20.0