mirror of https://bitbucket.org/ausocean/av.git
timing for 25 frames testing
This commit is contained in:
parent
61bb0b68f6
commit
44aac3f9fd
|
@ -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 }
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue