Update now gets a new instant (not with GetStreamInstant) and uses SaveStreamInstant to save

This commit is contained in:
BroodjeAap 2020-07-09 19:01:49 +00:00
parent 4a196a21b2
commit 8f4d46bc3f
2 changed files with 18 additions and 2 deletions

View file

@ -61,7 +61,7 @@ func (server Server) stream(w http.ResponseWriter, r *http.Request) {
gocv.CvtColor(diff, &diff, gocv.ColorBGRAToGray) gocv.CvtColor(diff, &diff, gocv.ColorBGRAToGray)
gocv.GaussianBlur(diff, &diff, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect) gocv.GaussianBlur(diff, &diff, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
go stream.SaveStreamInstant(URL, mat) go stream.SaveStreamInstant(mat)
if stream.PreviousInstantPathExists() { if stream.PreviousInstantPathExists() {
previous := stream.IMReadPrevious() previous := stream.IMReadPrevious()

View file

@ -2,6 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"image"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
@ -35,6 +36,21 @@ func NewStream(URL string) Stream {
// Update calls itself every Interval milliseconds // Update calls itself every Interval milliseconds
func (s Stream) Update() { func (s Stream) Update() {
log.Print("Update:", s.URL) log.Print("Update:", s.URL)
resp, err := http.Get(s.URL)
if err != nil {
log.Fatal(err)
}
img, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
if err != nil {
log.Fatal("Could not IMDecode img")
}
gocv.GaussianBlur(mat, &mat, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
go s.SaveStreamInstant(mat)
} }
// UpdateInterval calls Update() every interval // UpdateInterval calls Update() every interval
@ -63,7 +79,7 @@ func (s Stream) GetStreamInstant() gocv.Mat {
} }
// SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath // SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath
func (s Stream) SaveStreamInstant(URL string, mat gocv.Mat) { func (s Stream) SaveStreamInstant(mat gocv.Mat) {
streamStoreDir := s.GetStreamStoreDirPath() streamStoreDir := s.GetStreamStoreDirPath()
os.MkdirAll(streamStoreDir, os.ModePerm) os.MkdirAll(streamStoreDir, os.ModePerm)