diff --git a/main.go b/main.go index c870dec..7616ae3 100755 --- a/main.go +++ b/main.go @@ -61,7 +61,7 @@ func (server Server) stream(w http.ResponseWriter, r *http.Request) { gocv.CvtColor(diff, &diff, gocv.ColorBGRAToGray) 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() { previous := stream.IMReadPrevious() diff --git a/stream.go b/stream.go index a034229..7332eea 100755 --- a/stream.go +++ b/stream.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "image" "io/ioutil" "log" "net/http" @@ -35,6 +36,21 @@ func NewStream(URL string) Stream { // Update calls itself every Interval milliseconds func (s Stream) Update() { 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 @@ -63,7 +79,7 @@ func (s Stream) GetStreamInstant() gocv.Mat { } // 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() os.MkdirAll(streamStoreDir, os.ModePerm)