more testing

This commit is contained in:
Ella Pietraroia 2020-01-20 14:31:40 +10:30
parent 44aac3f9fd
commit c99d3564bf
1 changed files with 15 additions and 6 deletions

View File

@ -83,6 +83,7 @@ func (m *MOGFilter) Close() error {
// Write applies the motion filter to the video stream. Only frames with motion // Write applies the motion filter to the video stream. Only frames with motion
// are written to the destination encoder, frames without are discarded. // are written to the destination encoder, frames without are discarded.
func (m *MOGFilter) Write(f []byte) (int, error) { func (m *MOGFilter) Write(f []byte) (int, error) {
t2 := time.Now()
if frames == 0 { if frames == 0 {
t1 = time.Now() t1 = time.Now()
} }
@ -90,6 +91,7 @@ func (m *MOGFilter) Write(f []byte) (int, error) {
m.hold[m.hfCount] = f m.hold[m.hfCount] = f
m.hfCount++ m.hfCount++
frames++ frames++
fmt.Printf("Hold in array 1 frame:\t%dms\n", time.Now().Sub(t2).Milliseconds())
if frames >= 24 { if frames >= 24 {
fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds()) fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds())
frames = 0 frames = 0
@ -148,13 +150,15 @@ func (m *MOGFilter) Write(f []byte) (int, error) {
// Don't write to destination if there is no motion. // Don't write to destination if there is no motion.
if len(contours) == 0 { if len(contours) == 0 {
return 0, nil
}
frames++ frames++
fmt.Printf("No motion 1 frame:\t%dms\n", time.Now().Sub(t2).Milliseconds())
if frames >= 24 { if frames >= 24 {
fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds()) fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds())
frames = 0 frames = 0
} }
return 0, nil
}
// Write to destination, past 4 frames then current frame. // Write to destination, past 4 frames then current frame.
for i, h := range m.hold { for i, h := range m.hold {
_, err := m.dst.Write(h) _, err := m.dst.Write(h)
@ -163,7 +167,12 @@ func (m *MOGFilter) Write(f []byte) (int, error) {
return 0, err return 0, err
} }
} }
fmt.Printf("Motion 1 frame:\t\t%dms\n", time.Now().Sub(t2).Milliseconds())
frames++
if frames >= 24 {
fmt.Printf("25 frames takes: %dms\n\n", time.Now().Sub(t1).Milliseconds())
frames = 0
}
return m.dst.Write(f) return m.dst.Write(f)
} }