mirror of https://bitbucket.org/ausocean/av.git
iteration error fix
This commit is contained in:
parent
0189fad0e2
commit
2c947edc2b
|
@ -58,6 +58,8 @@ type Basic struct {
|
|||
img image.Image
|
||||
bg [][]pixel
|
||||
bwImg *image.RGBA
|
||||
thresh int
|
||||
pix int
|
||||
w int
|
||||
h int
|
||||
file io.WriteCloser
|
||||
|
@ -66,7 +68,7 @@ type Basic struct {
|
|||
}
|
||||
|
||||
// NewBasic returns a pointer to a new Basic filter struct.
|
||||
func NewBasic(dst io.WriteCloser, debug bool) *Basic {
|
||||
func NewBasic(dst io.WriteCloser, debug bool, t, p int) *Basic {
|
||||
bwImg := image.NewRGBA(image.Rect(0, 0, 0, 0))
|
||||
var file io.WriteCloser
|
||||
var err error
|
||||
|
@ -77,7 +79,7 @@ func NewBasic(dst io.WriteCloser, debug bool) *Basic {
|
|||
panic(fmt.Sprintf("could not create debug file: %v", err))
|
||||
}
|
||||
}
|
||||
return &Basic{dst, nil, nil, bwImg, 0, 0, file, 0, debug}
|
||||
return &Basic{dst, nil, nil, bwImg, t, p, 0, 0, file, 0, debug}
|
||||
}
|
||||
|
||||
// Implements io.Closer.
|
||||
|
@ -108,14 +110,14 @@ func (bf *Basic) Write(f []byte) (int, error) {
|
|||
bf.bwImg = image.NewRGBA(image.Rect(0, 0, bf.w, bf.h))
|
||||
|
||||
bf.bg = make([][]pixel, bf.h)
|
||||
for i, _ := range bf.bg {
|
||||
bf.bg[i] = make([]pixel, bf.w)
|
||||
for j, _ := range bf.bg[i] {
|
||||
for j, _ := range bf.bg {
|
||||
bf.bg[j] = make([]pixel, bf.w)
|
||||
for i, _ := range bf.bg[j] {
|
||||
p := bf.img.At(i, j)
|
||||
r, g, b, _ := p.RGBA()
|
||||
bf.bg[i][j].r = r
|
||||
bf.bg[i][j].b = b
|
||||
bf.bg[i][j].g = g
|
||||
bf.bg[j][i].r = r
|
||||
bf.bg[j][i].b = b
|
||||
bf.bg[j][i].g = g
|
||||
}
|
||||
}
|
||||
return len(f), nil
|
||||
|
@ -124,14 +126,14 @@ func (bf *Basic) Write(f []byte) (int, error) {
|
|||
// Use 4x goroutines to each process one row of pixels.
|
||||
var j int
|
||||
j = 0
|
||||
var wg *sync.WaitGroup
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for j < bf.h {
|
||||
wg.Add(4)
|
||||
go bf.process(j, wg)
|
||||
go bf.process(j+1, wg)
|
||||
go bf.process(j+2, wg)
|
||||
go bf.process(j+3, wg)
|
||||
go bf.process(j, &wg)
|
||||
go bf.process(j+1, &wg)
|
||||
go bf.process(j+2, &wg)
|
||||
go bf.process(j+3, &wg)
|
||||
j = j + 4
|
||||
wg.Wait()
|
||||
}
|
||||
|
@ -189,9 +191,9 @@ func (bf *Basic) process(j int, wg *sync.WaitGroup) {
|
|||
}
|
||||
|
||||
// Update backgound image.
|
||||
bf.bg[i][j].r = r
|
||||
bf.bg[i][j].b = b
|
||||
bf.bg[i][j].g = g
|
||||
bf.bg[j][i].r = r
|
||||
bf.bg[j][i].b = b
|
||||
bf.bg[j][i].g = g
|
||||
}
|
||||
wg.Done()
|
||||
}
|
||||
|
|
|
@ -106,6 +106,10 @@ const (
|
|||
defaultMOGMinArea = 25.0
|
||||
defaultMOGThreshold = 20.0
|
||||
defaultMOGHistory = 500
|
||||
|
||||
// Basic filter parameter defaults
|
||||
defaultBasicThreshold = 45000
|
||||
defaultBasicPixels = 1000
|
||||
)
|
||||
|
||||
// Quality represents video quality.
|
||||
|
@ -301,6 +305,9 @@ type Config struct {
|
|||
MOGThreshold float64 // Intensity value from the KNN motion detection algorithm that is considered motion.
|
||||
MOGHistory uint // Length of MOG filter's history
|
||||
|
||||
BasicThreshold int
|
||||
BasicPixels int
|
||||
|
||||
// If true will restart reading of input after an io.EOF.
|
||||
Loop bool
|
||||
|
||||
|
@ -314,6 +321,8 @@ type Config struct {
|
|||
// can be set over the web. It is a psuedo const.
|
||||
var TypeData = map[string]string{
|
||||
"AutoWhiteBalance": "enum:off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon",
|
||||
"BasicPixels": "int",
|
||||
"BasicThreshold": "int",
|
||||
"BitDepth": "int",
|
||||
"Brightness": "uint",
|
||||
"BurstPeriod": "uint",
|
||||
|
@ -525,6 +534,16 @@ func (c *Config) Validate() error {
|
|||
c.MOGHistory = defaultMOGHistory
|
||||
}
|
||||
|
||||
if c.BasicThreshold <= 0 {
|
||||
c.logInvalidField("BasicThreshold", defaultBasicThreshold)
|
||||
c.BasicThreshold = defaultBasicThreshold
|
||||
}
|
||||
|
||||
if c.BasicPixels <= 0 {
|
||||
c.logInvalidField("BasicPixels", defaultBasicPixels)
|
||||
c.BasicPixels = defaultBasicPixels
|
||||
}
|
||||
|
||||
if c.ShowWindows {
|
||||
os, err := osName()
|
||||
if err != nil {
|
||||
|
|
|
@ -349,7 +349,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
|||
case config.FilterDifference:
|
||||
r.filters[i] = filter.NewDifference(dst, r.cfg.ShowWindows, r.cfg.DiffThreshold)
|
||||
case config.FilterBasic:
|
||||
r.filters[i] = filter.NewBasic(dst, r.cfg.ShowWindows)
|
||||
r.filters[i] = filter.NewBasic(dst, r.cfg.ShowWindows, r.cfg.BasicThreshold, r.cfg.BasicPixels)
|
||||
default:
|
||||
panic("Undefined Filter")
|
||||
}
|
||||
|
@ -860,6 +860,21 @@ func (r *Revid) Update(vars map[string]string) error {
|
|||
break
|
||||
}
|
||||
r.cfg.MOGHistory = uint(v)
|
||||
|
||||
case "BasicThreshold":
|
||||
v, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid BasicThreshold var", "value", value)
|
||||
break
|
||||
}
|
||||
r.cfg.BasicThreshold = v
|
||||
case "BasicPixels":
|
||||
v, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid BasicPixels var", "value", value)
|
||||
break
|
||||
}
|
||||
r.cfg.BasicPixels = v
|
||||
case "FileFPS":
|
||||
v, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue