implement frameskip for motion detection

reduce power consumption
This commit is contained in:
Steven Polley 2020-10-29 04:32:45 +00:00
parent 300367c00b
commit d22a376146

View File

@ -14,7 +14,7 @@ import (
const (
minimumMotionArea = 3000 // Motion detection minimum area needed to move
recordLengthAfterMotion = 30 // Number of seconds to keep recording going after motion was last detected
motionDetectInterval = 1 //number of seconds between motion detection attempts // TBD: Implement this, currently does nothing
motionDetectInterval = 30 //number of frames between motion detection attempts // TBD: Implement this, currently does nothing
)
var (
@ -65,6 +65,8 @@ func main() {
detectMotion(img)
}
frameCount := 0
// main loop
for {
if ok := webcam.Read(&img); !ok {
@ -75,6 +77,7 @@ func main() {
continue
}
if frameCount >= motionDetectInterval {
if detectMotion(img) {
// Determine if a new recording needs to start
if time.Now().After(lastMotionDetectedTime.Add(time.Second * recordLengthAfterMotion)) {
@ -89,6 +92,8 @@ func main() {
// And always update the timestamp
lastMotionDetectedTime = time.Now()
}
frameCount = 0
}
// Determine if we are currently recording and if so, then save the frame to the video
if currentRecording != nil {