refactor CopyYCbCr

This commit is contained in:
Jehiah Czebotar
2017-05-07 16:24:37 -04:00
parent 89495ccced
commit 45504639a9
2 changed files with 20 additions and 9 deletions

View File

@@ -0,0 +1,16 @@
package main
import (
"image"
)
// CopyYCbCr returns a deep copy of i
//
// This is useful when the backing slice needs to be copied
func CopyYCbCr(i image.YCbCr) *image.YCbCr {
f := image.NewYCbCr(i.Bounds(), i.SubsampleRatio)
copy(f.Y, i.Y)
copy(f.Cb, i.Cb)
copy(f.Cr, i.Cr)
return f
}

View File

@@ -137,7 +137,7 @@ func (p *Project) Run() error {
interested := true
switch {
case frame == 0:
case p.Step == 5 && len(bg) < bgFrameCount && frame%15 == 0:
case p.Step == 5 && len(bg) < bgFrameCount && frame%5 == 0:
default:
interested = false
}
@@ -199,14 +199,9 @@ func (p *Project) Run() error {
p.Response.Step4Img = dataImgFromBytes(imgBytes)
}
}
if p.Step == 5 && len(bg) < bgFrameCount && frame%15 == 0 {
// calculate the background
// background_img
bgframe := image.NewYCbCr(vf.Image.Bounds(), vf.Image.SubsampleRatio)
copy(bgframe.Y, vf.Image.Y)
copy(bgframe.Cb, vf.Image.Cb)
copy(bgframe.Cr, vf.Image.Cr)
bg = append(bg, bgframe)
if p.Step == 5 && len(bg) < bgFrameCount && frame%5 == 0 {
// queue frames to be used in background calculation
bg = append(bg, CopyYCbCr(vf.Image))
// debugImg, err := dataImgWithSize(bgframe, 400, 300)
// if err != nil {
// return err