Update now gets a new instant (not with GetStreamInstant) and uses SaveStreamInstant to save
This commit is contained in:
parent
4a196a21b2
commit
8f4d46bc3f
2 changed files with 18 additions and 2 deletions
2
main.go
2
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()
|
||||
|
|
18
stream.go
18
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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue