From dd86398394e3afed2afd6ee8051c1f1dc5ec032c Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Sat, 11 Jul 2020 11:15:07 +0000 Subject: [PATCH] removed instant update stuff from stream --- main.go | 20 +------------------- stream.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index e392dc4..9f26a04 100755 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - "image" "io/ioutil" "log" "net/http" @@ -58,24 +57,7 @@ func (server Server) stream(w http.ResponseWriter, r *http.Request) { return } - mat := stream.GetStreamInstant() - - diff := gocv.NewMat() - mat.CopyTo(&diff) - gocv.CvtColor(diff, &diff, gocv.ColorBGRAToGray) - gocv.GaussianBlur(diff, &diff, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect) - - go stream.SaveStreamInstant(mat) - - if stream.PreviousInstantPathExists() { - previous := stream.IMReadPrevious() - - gocv.GaussianBlur(previous, &previous, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect) - - gocv.AbsDiff(previous, diff, &diff) - - gocv.Threshold(diff, &diff, 25, 255, gocv.ThresholdBinary) - } + mat := stream.IMReadCurrentColor() jpg, err := gocv.IMEncode(".jpg", mat) if err != nil { diff --git a/stream.go b/stream.go index 4a8e5ac..59327a9 100755 --- a/stream.go +++ b/stream.go @@ -51,10 +51,19 @@ func (s Stream) Update() { } go gocv.IMWrite(s.GetCurrentColorInstantPath(), mat) - grey := gocv.NewMat() - gocv.CvtColor(mat, &grey, gocv.ColorBGRAToGray) - gocv.GaussianBlur(grey, &grey, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect) - go s.SaveStreamInstant(grey) + currentGrey := gocv.NewMat() + gocv.CvtColor(mat, ¤tGrey, gocv.ColorBGRAToGray) + gocv.GaussianBlur(currentGrey, ¤tGrey, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect) + go s.SaveStreamInstant(currentGrey) + + if !s.PreviousInstantPathExists() { + return + } + + diff := gocv.NewMat() + previousGrey := s.IMReadPrevious() + gocv.AbsDiff(previousGrey, currentGrey, &diff) + gocv.Threshold(diff, &diff, 10, 255, gocv.ThresholdBinary) } // UpdateInterval calls Update() every interval