Skip to content

Commit

Permalink
removed edge pixels from background calc (#118)
Browse files Browse the repository at this point in the history
* removed edge pixels from background calc and add test
  • Loading branch information
GP authored Dec 6, 2020
1 parent 23e3721 commit 589367d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.12.x"
- "1.15.x"

script:
- go mod tidy
Expand All @@ -17,4 +17,4 @@ deploy:
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
go: "1.12.x"
go: "1.15.x"
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/TheCacophonyProject/thermal-recorder

go 1.12
go 1.15

require (
github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231
github.com/TheCacophonyProject/go-config v1.6.0
github.com/TheCacophonyProject/go-config v1.6.3
github.com/TheCacophonyProject/go-cptv v0.0.0-20201110014247-4e8fc2c763ab
github.com/TheCacophonyProject/lepton3 v0.0.0-20200909032119-e2b2b778a8ee
github.com/TheCacophonyProject/window v0.0.0-20200312071457-7fc8799fdce7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/TheCacophonyProject/go-api v0.0.0-20190923033957-174cea2ac81c/go.mod
github.com/TheCacophonyProject/go-config v0.0.0-20190922224052-7c2a21bc6b88/go.mod h1:gPUJLVu408NRz9/P3BrsxzOzLc+KJLrv+jVdDw3RI0Y=
github.com/TheCacophonyProject/go-config v1.4.0 h1:G7YOqMrRljWQ0BWVHJiZNe79KaMNJMP5QyCa2fP27cs=
github.com/TheCacophonyProject/go-config v1.4.0/go.mod h1:oARW/N3eJbcewCqB+Jc7TBwuODawwYgpo56UO6yBdKU=
github.com/TheCacophonyProject/go-config v1.6.0 h1:iCejQaBh9JhW9/5NAy2d7wOK4YbR4vx1Efgr4nbDCvk=
github.com/TheCacophonyProject/go-config v1.6.0/go.mod h1:eDQfBjmTDh/l+2QLBgsotmJFd/1x/7w4SwwBUxMM86w=
github.com/TheCacophonyProject/go-config v1.6.3 h1:2g3mKWBF4wiHtXL8W86k/Q8iLN5b98tO04onJPMKFmM=
github.com/TheCacophonyProject/go-config v1.6.3/go.mod h1:eDQfBjmTDh/l+2QLBgsotmJFd/1x/7w4SwwBUxMM86w=
github.com/TheCacophonyProject/go-cptv v0.0.0-20200116020937-858bd8b71512/go.mod h1:8H6Aaft5549sIWxcsuCIL2o60/TQkoF93fVoSTpgZb8=
github.com/TheCacophonyProject/go-cptv v0.0.0-20200616224711-fc633122087a/go.mod h1:Vg73Ezn4kr8qDNP9LNgjki9qgi+5T/0Uc9oDyflaYUY=
github.com/TheCacophonyProject/go-cptv v0.0.0-20200818214604-bd5d4aa36043/go.mod h1:wG4/P/TsGtk33uBClYPjRlSbcdQrIASXutOUV8LMn2o=
Expand Down
23 changes: 21 additions & 2 deletions motion/motion.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,18 @@ func (d *motionDetector) warmerDiffFrames(a, b, out *cptvframe.Frame) *cptvframe
func (d *motionDetector) updateBackground(new_frame *cptvframe.Frame, prevFFC bool) (float64, bool) {
d.backgroundFrames++
if d.backgroundFrames == 1 {
for i := range new_frame.Pix {
copy(d.background.Pix[i], new_frame.Pix[i])
for y := d.start; y < d.rowStop; y++ {
copy(d.background.Pix[y][d.start:d.columnStop], new_frame.Pix[y][d.start:d.columnStop])
for x := 0; x < d.start; x++ {
d.background.Pix[y][x] = new_frame.Pix[y][d.start]
d.background.Pix[y][d.columnStop+x] = new_frame.Pix[y][d.columnStop-1]
}
}
for y := 0; y < d.start; y++ {
copy(d.background.Pix[y], d.background.Pix[d.start])
copy(d.background.Pix[d.rowStop+y], d.background.Pix[d.rowStop-1])
}

return 0, true
}

Expand All @@ -269,8 +278,18 @@ func (d *motionDetector) updateBackground(new_frame *cptvframe.Frame, prevFFC bo
d.backgroundWeight[y][x] = weight
}
average = average + float64(d.background.Pix[y][x])/d.numPixels
for x := 0; x < d.start; x++ {
// copy valid pixels into edge pixels
d.background.Pix[y][x] = d.background.Pix[y][d.start]
d.background.Pix[y][d.columnStop+x] = d.background.Pix[y][d.columnStop-1]
}
}
}
// copy valid pixels into edge pixels
for y := 0; y < d.start; y++ {
copy(d.background.Pix[y], d.background.Pix[d.start])
copy(d.background.Pix[d.rowStop+y], d.background.Pix[d.rowStop-1])
}
return average, changed
}

Expand Down
44 changes: 44 additions & 0 deletions motion/motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,50 @@ func TestDetectsAfterEdgePixel(t *testing.T) {
assert.Equal(t, []int{0, 6, 6, 6}, pixels)
}

func TestBackgroundEdges(t *testing.T) {
camera := new(TestCamera)

config := defaultMotionParams()
config.EdgePixels = 2
detector := NewMotionDetector(config, defaultPreviewFrames(), camera)

edgeValue := uint16(999)
backgroundValue := 3000
g := newFrameGen(detector, camera)
frame := g.setupFrame(backgroundValue)
SetFrameEdge(frame, config.EdgePixels, edgeValue)

detector.updateBackground(frame, false)
for y := range frame.Pix {
for x := 0; x < len(frame.Pix[y]); x++ {
assert.Equal(t, detector.background.Pix[y][x], uint16(backgroundValue))
}
}
edgeValue = 100
backgroundValue = 2000
frame = g.setupFrame(backgroundValue)
SetFrameEdge(frame, config.EdgePixels, edgeValue)
detector.updateBackground(frame, false)

for y := range frame.Pix {
for x := 0; x < len(frame.Pix[y]); x++ {
assert.Equal(t, detector.background.Pix[y][x], uint16(backgroundValue))
}
}
}

func SetFrameEdge(frame *cptvframe.Frame, edges int, edgeValue uint16) {
for y := range frame.Pix {
cols := edges
if y < edges || y >= len(frame.Pix)-edges {
cols = len(frame.Pix[y])
}
for x := 0; x < cols; x++ {
frame.Pix[y][x] = edgeValue
}
}
}

func TestCanChangeEdgePixelsValue(t *testing.T) {
camera := new(TestCamera)

Expand Down

0 comments on commit 589367d

Please sign in to comment.