filter/mog.go: handles error from IMGDecode

This commit is contained in:
Scott 2019-12-31 15:30:51 +10:30
parent a62c25af41
commit 29443bd61f
1 changed files with 5 additions and 1 deletions

View File

@ -29,6 +29,7 @@ LICENSE
package filter package filter
import ( import (
"fmt"
"image" "image"
"image/color" "image/color"
"io" "io"
@ -74,7 +75,10 @@ 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) {
img, _ := gocv.IMDecode(f, gocv.IMReadColor) img, err := gocv.IMDecode(f, gocv.IMReadColor)
if err != nil {
return -1, fmt.Errorf("image can't be decoded: %w", err)
}
defer img.Close() defer img.Close()
imgDelta := gocv.NewMat() imgDelta := gocv.NewMat()