mirror of https://bitbucket.org/ausocean/av.git
filter: Difference → Diff
This commit is contained in:
parent
a41033beb3
commit
fa15d92388
|
@ -39,25 +39,25 @@ import (
|
|||
|
||||
const defaultDiffThreshold = 3
|
||||
|
||||
// Difference is a filter that provides basic motion detection. Difference calculates
|
||||
// Diff is a filter that provides basic motion detection. Difference calculates
|
||||
// the absolute difference for each pixel between two frames, then finds the mean. If
|
||||
// the mean is above a given threshold, then it is considered motion.
|
||||
type Difference struct {
|
||||
type Diff struct {
|
||||
debugging debugWindows
|
||||
dst io.WriteCloser
|
||||
thresh float64
|
||||
prev gocv.Mat
|
||||
}
|
||||
|
||||
// NewDifference returns a pointer to a new Difference struct.
|
||||
func NewDifference(dst io.WriteCloser, c config.Config) *Difference {
|
||||
// NewDiff returns a pointer to a new Diff struct.
|
||||
func NewDiff(dst io.WriteCloser, c config.Config) *Diff {
|
||||
// Validate parameters.
|
||||
if c.MotionThreshold <= 0 {
|
||||
c.LogInvalidField("MotionThreshold", defaultDiffThreshold)
|
||||
c.MotionThreshold = defaultDiffThreshold
|
||||
}
|
||||
|
||||
return &Difference{
|
||||
return &Diff{
|
||||
dst: dst,
|
||||
thresh: c.MotionThreshold,
|
||||
prev: gocv.NewMat(),
|
||||
|
@ -68,7 +68,7 @@ func NewDifference(dst io.WriteCloser, c config.Config) *Difference {
|
|||
// Implements io.Closer.
|
||||
// Close frees resources used by gocv, because it has to be done manually, due to
|
||||
// it using c-go.
|
||||
func (d *Difference) Close() error {
|
||||
func (d *Diff) Close() error {
|
||||
d.prev.Close()
|
||||
d.debugging.close()
|
||||
return nil
|
||||
|
@ -77,7 +77,7 @@ func (d *Difference) Close() error {
|
|||
// Implements io.Writer.
|
||||
// Write applies the motion filter to the video stream. Only frames with motion
|
||||
// are written to the destination encoder, frames without are discarded.
|
||||
func (d *Difference) Write(f []byte) (int, error) {
|
||||
func (d *Diff) Write(f []byte) (int, error) {
|
||||
if d.prev.Empty() {
|
||||
var err error
|
||||
d.prev, err = gocv.IMDecode(f, gocv.IMReadColor)
|
||||
|
|
|
@ -44,8 +44,8 @@ func NewKNN(dst io.WriteCloser, c config.Config) *NoOp {
|
|||
return &NoOp{dst: dst}
|
||||
}
|
||||
|
||||
// NewDiffference returns a pointer to a new NoOp struct for testing purposes only.
|
||||
func NewDifference(dst io.WriteCloser, c config.Config) *NoOp {
|
||||
// NewDiff returns a pointer to a new NoOp struct for testing purposes only.
|
||||
func NewDiff(dst io.WriteCloser, c config.Config) *NoOp {
|
||||
return &NoOp{dst: dst}
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ const (
|
|||
FilterMOG
|
||||
FilterVariableFPS
|
||||
FilterKNN
|
||||
FilterDifference
|
||||
FilterDiff
|
||||
FilterBasic
|
||||
)
|
||||
|
||||
|
|
|
@ -339,8 +339,8 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
|||
r.filters[i] = filter.NewVariableFPS(dst, r.cfg.MinFPS, filter.NewMOG(dst, r.cfg))
|
||||
case config.FilterKNN:
|
||||
r.filters[i] = filter.NewKNN(dst, r.cfg)
|
||||
case config.FilterDifference:
|
||||
r.filters[i] = filter.NewDifference(dst, r.cfg)
|
||||
case config.FilterDiff:
|
||||
r.filters[i] = filter.NewDiff(dst, r.cfg)
|
||||
case config.FilterBasic:
|
||||
r.filters[i] = filter.NewBasic(dst, r.cfg)
|
||||
default:
|
||||
|
@ -676,7 +676,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
|||
}
|
||||
case "Filters":
|
||||
filters := strings.Split(value, ",")
|
||||
m := map[string]int{"NoOp": config.FilterNoOp, "MOG": config.FilterMOG, "VariableFPS": config.FilterVariableFPS, "KNN": config.FilterKNN, "Difference": config.FilterDifference, "Basic": config.FilterBasic}
|
||||
m := map[string]int{"NoOp": config.FilterNoOp, "MOG": config.FilterMOG, "VariableFPS": config.FilterVariableFPS, "KNN": config.FilterKNN, "Difference": config.FilterDiff, "Basic": config.FilterBasic}
|
||||
r.cfg.Filters = make([]int, len(filters))
|
||||
for i, filter := range filters {
|
||||
v, ok := m[filter]
|
||||
|
|
Loading…
Reference in New Issue