From 44aac3f9fd115a6934c5a7e9e6c83b3cee027b34 Mon Sep 17 00:00:00 2001 From: Ella Pietraroia Date: Mon, 20 Jan 2020 14:09:42 +1030 Subject: [PATCH] timing for 25 frames testing --- filter/filter.go | 14 +++++++++++++- filter/mog.go | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/filter/filter.go b/filter/filter.go index ec182531..c6fec897 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -27,7 +27,9 @@ LICENSE package filter import ( + "fmt" "io" + "time" ) // Interface for all filters. @@ -44,6 +46,16 @@ type NoOp struct { func NewNoOp(dst io.Writer) *NoOp { return &NoOp{dst: dst} } -func (n *NoOp) Write(p []byte) (int, error) { return n.dst.Write(p) } +func (n *NoOp) Write(p []byte) (int, error) { + if frames == 0 { + t1 = time.Now() + } + frames++ + if frames >= 24 { + fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds()) + frames = 0 + } + return n.dst.Write(p) +} func (n *NoOp) Close() error { return nil } diff --git a/filter/mog.go b/filter/mog.go index 1b8003a5..7711c101 100644 --- a/filter/mog.go +++ b/filter/mog.go @@ -33,6 +33,7 @@ import ( "image" "image/color" "io" + "time" "gocv.io/x/gocv" ) @@ -51,6 +52,9 @@ type MOGFilter struct { hfCount int } +var frames int = 0 +var t1 = time.Now() + // NewMOGFilter returns a pointer to a new MOGFilter struct. func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *MOGFilter { bs := gocv.NewBackgroundSubtractorMOG2WithParams(history, threshold, false) @@ -79,9 +83,17 @@ func (m *MOGFilter) Close() error { // 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) { + if frames == 0 { + t1 = time.Now() + } if m.hfCount < (m.hf - 1) { m.hold[m.hfCount] = f m.hfCount++ + frames++ + if frames >= 24 { + fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds()) + frames = 0 + } return 0, nil } @@ -138,7 +150,11 @@ func (m *MOGFilter) Write(f []byte) (int, error) { if len(contours) == 0 { return 0, nil } - + frames++ + if frames >= 24 { + fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds()) + frames = 0 + } // Write to destination, past 4 frames then current frame. for i, h := range m.hold { _, err := m.dst.Write(h)