Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tester #125

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cmd/thermal-recorder/cptvplaybacktester.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
cptv "github.com/TheCacophonyProject/go-cptv"
"github.com/TheCacophonyProject/go-cptv/cptvframe"
"github.com/TheCacophonyProject/lepton3"
"gopkg.in/yaml.v1"

"github.com/TheCacophonyProject/thermal-recorder/motion"
"github.com/TheCacophonyProject/thermal-recorder/recorder"
Expand Down Expand Up @@ -154,7 +155,6 @@ func (cpt *CPTVPlaybackTester) Detect(filename string) *EventLoggingRecordingLis
listener.verbose = verbose
listener.framesHz = camera.FPS()
processor := motion.NewMotionProcessor(lepton3.ParseRawFrame, &cpt.config.Motion, &cpt.config.Recorder, &cpt.config.Location, listener, recorder, camera)

if err != nil {
log.Printf("Could not open file %v", err)
}
Expand All @@ -163,6 +163,14 @@ func (cpt *CPTVPlaybackTester) Detect(filename string) *EventLoggingRecordingLis
log.Printf("Device name: %v", reader.DeviceName())
log.Printf("Timestamp: %v", reader.Timestamp())

// load thresh used for recording
motionConfig := make(map[string]interface{})
err = yaml.Unmarshal([]byte(reader.MotionConfig()), &motionConfig)
if trigThresh, ok := motionConfig["triggeredthresh"]; ok {
processor.SetTempThresh(uint16(trigThresh.(int)))
log.Printf("Triggered thresh: %v", trigThresh)
}

fakeTime := time.Minute
frame := reader.EmptyFrame()
for {
Expand All @@ -183,9 +191,13 @@ func (cpt *CPTVPlaybackTester) Detect(filename string) *EventLoggingRecordingLis
if frame.Status.TimeOn == time.Duration(0) {
frame.Status.TimeOn = fakeTime
}
if frame.Status.BackgroundFrame {
processor.SetBackground(frame)
} else {

processor.ProcessFrame(frame)
listener.frameCount++
processor.ProcessFrame(frame)
listener.frameCount++
}
}
}

Expand Down
56 changes: 27 additions & 29 deletions motion/motion.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ import (
// Field Correction.
// TODO - this should probably be configurable (although 10s does seem right).
const ffcPeriod = 10 * time.Second

const debugLogSecs = 5
const frameBackgroundWeighting = 0.99
const weightEveryNFrames = 3
const weightPercent = 0.002

func NewMotionDetector(args config.ThermalMotion, previewFrames int, camera cptvframe.CameraSpec) *motionDetector {
d := new(motionDetector)
Expand Down Expand Up @@ -62,34 +60,35 @@ func NewMotionDetector(args config.ThermalMotion, previewFrames int, camera cptv
for i := range d.backgroundWeight {
d.backgroundWeight[i] = make([]float32, camera.ResX())
}

d.backgroundWeighting = weightPercent * float32(d.deltaThresh)
return d
}

type motionDetector struct {
flooredFrames FrameLoop
diffFrames FrameLoop
firstDiff bool
dynamicThresh bool
useOneDiff bool
tempThresh uint16
tempThreshMax uint16
tempThreshMin uint16
deltaThresh uint16
countThresh int
warmerOnly bool
start int
rowStop int
columnStop int
count int
background *cptvframe.Frame
backgroundWeight [][]float32
backgroundFrames int
debug *debugTracker
previewFrames int
numPixels float64
affectedByFCC bool
framesHz int
flooredFrames FrameLoop
diffFrames FrameLoop
firstDiff bool
dynamicThresh bool
useOneDiff bool
tempThresh uint16
tempThreshMax uint16
tempThreshMin uint16
deltaThresh uint16
countThresh int
warmerOnly bool
start int
rowStop int
columnStop int
count int
background *cptvframe.Frame
backgroundWeight [][]float32
backgroundFrames int
backgroundWeighting float32
debug *debugTracker
previewFrames int
numPixels float64
affectedByFCC bool
framesHz int
}

func (d *motionDetector) Reset(camera cptvframe.CameraSpec) {
Expand Down Expand Up @@ -278,7 +277,7 @@ func (d *motionDetector) updateBackground(new_frame *cptvframe.Frame, prevFFC bo
d.backgroundWeight[y][x] = 0
changed = true
} else {
weight += 0.1
weight += d.backgroundWeighting
if weight > math.MaxFloat32 {
weight = math.MaxFloat32
}
Expand Down Expand Up @@ -311,7 +310,6 @@ func absDiff(a, b uint16) uint16 {

func warmerDiff(a, b uint16) uint16 {
d := int32(a) - int32(b)

if d < 0 {
return 0
}
Expand Down
9 changes: 9 additions & 0 deletions motion/motionprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ type RecordingListener interface {
RecordingEnded()
}

func (d *MotionProcessor) SetTempThresh(tempThresh uint16) {
d.motionDetector.tempThresh = tempThresh
d.motionDetector.deltaThresh = 100
}

func (d *MotionProcessor) SetBackground(frame *cptvframe.Frame) {
d.motionDetector.background.Pix = frame.Pix
}

func (mp *MotionProcessor) Reset(camera cptvframe.CameraSpec) {
mp.stopRecording()
mp.motionDetector.Reset(camera)
Expand Down