mirror of
https://github.com/jehiah/TrafficSpeed.git
synced 2025-12-24 12:47:54 +08:00
refactor CopyYCbCr
This commit is contained in:
16
src/cmd/open_speed_data/image_utils.go
Normal file
16
src/cmd/open_speed_data/image_utils.go
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user