mirror of https://bitbucket.org/ausocean/av.git
Merged in MOG-err-imgdecode (pull request #319)
filter/mog.go: handles error from IMGDecode Approved-by: Saxon Milton <saxon.milton@gmail.com>
This commit is contained in:
commit
474b58d616
|
@ -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 0, fmt.Errorf("image can't be decoded: %w", err)
|
||||||
|
}
|
||||||
defer img.Close()
|
defer img.Close()
|
||||||
|
|
||||||
imgDelta := gocv.NewMat()
|
imgDelta := gocv.NewMat()
|
||||||
|
@ -121,7 +125,7 @@ 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 -1, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to destination.
|
// Write to destination.
|
||||||
|
|
Loading…
Reference in New Issue