diff --git a/main.go b/main.go
index dbc53c4..e392dc4 100755
--- a/main.go
+++ b/main.go
@@ -84,6 +84,69 @@ func (server Server) stream(w http.ResponseWriter, r *http.Request) {
w.Write(jpg)
}
+func (server Server) previous(w http.ResponseWriter, r *http.Request) {
+ if r.FormValue("URL") == "" {
+ return
+ }
+ w.Header().Set("Content-Type", "image/jpeg")
+ URL := r.FormValue("URL")
+
+ stream, exists := server.Streams[URL]
+ if !exists {
+ return
+ }
+ if !stream.PreviousInstantPathExists() {
+ return
+ }
+ jpg, err := gocv.IMEncode(".jpg", stream.IMReadPrevious())
+ if err != nil {
+ log.Fatal("Could not encode Mat to jpg:", URL)
+ }
+ w.Write(jpg)
+}
+
+func (server Server) currentColor(w http.ResponseWriter, r *http.Request) {
+ if r.FormValue("URL") == "" {
+ return
+ }
+ w.Header().Set("Content-Type", "image/jpeg")
+ URL := r.FormValue("URL")
+
+ stream, exists := server.Streams[URL]
+ if !exists {
+ return
+ }
+ if !stream.CurrentColorInstantPathExists() {
+ return
+ }
+ jpg, err := gocv.IMEncode(".jpg", stream.IMReadCurrentColor())
+ if err != nil {
+ log.Fatal("Could not encode Mat to jpg:", URL)
+ }
+ w.Write(jpg)
+}
+
+func (server Server) current(w http.ResponseWriter, r *http.Request) {
+ if r.FormValue("URL") == "" {
+ return
+ }
+ w.Header().Set("Content-Type", "image/jpeg")
+ URL := r.FormValue("URL")
+
+ stream, exists := server.Streams[URL]
+ if !exists {
+ return
+ }
+ if !stream.CurrentInstantPathExists() {
+ return
+ }
+ jpg, err := gocv.IMEncode(".jpg", stream.IMReadCurrent())
+ if err != nil {
+ log.Fatal("Could not encode Mat to jpg:", URL)
+ }
+ w.Write(jpg)
+}
+
func main() {
staticFileServer := http.FileServer(http.Dir("./static"))
http.Handle("/static/", http.StripPrefix("/static/", staticFileServer))
@@ -110,5 +173,8 @@ func main() {
http.HandleFunc("/", server.index)
http.HandleFunc("/stream", server.stream)
+ http.HandleFunc("/previous", server.previous)
+ http.HandleFunc("/current_color", server.currentColor)
+ http.HandleFunc("/current", server.current)
log.Fatal(http.ListenAndServe(":8080", nil))
}
diff --git a/stream.go b/stream.go
index 6978c57..adb60af 100755
--- a/stream.go
+++ b/stream.go
@@ -45,14 +45,16 @@ func (s Stream) Update() {
img, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
- mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
+ mat, err := gocv.IMDecode(img, gocv.IMReadColor)
if err != nil {
log.Fatal("Could not IMDecode img")
}
+ go gocv.IMWrite(s.GetCurrentColorInstantPath(), mat)
+ grey := gocv.NewMat()
+ gocv.CvtColor(mat, &grey, gocv.ColorBGRAToBGR)
gocv.GaussianBlur(mat, &mat, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
-
- go s.SaveStreamInstant(mat)
+ go s.SaveStreamInstant(grey)
}
// UpdateInterval calls Update() every interval
@@ -162,6 +164,21 @@ func (s Stream) IMReadCurrent() gocv.Mat {
return gocv.IMRead(s.GetCurrentInstantPath(), gocv.IMReadGrayScale)
}
+// GetCurrentColorInstantPath returns filepath.Join(s.GetStreamDirPath(), s.Base64, "current_color.jpg")
+func (s Stream) GetCurrentColorInstantPath() string {
+ return filepath.Join(s.GetStreamStoreDirPath(), "current_color.jpg")
+}
+
+// CurrentColorInstantPathExists returns FileExists(GetCurrentColorInstantPath())
+func (s Stream) CurrentColorInstantPathExists() bool {
+ return FileExists(s.GetCurrentColorInstantPath())
+}
+
+// IMReadCurrentColor returns gocv.IMRead(GetCurrentColorInstantPath(), gocv.IMReadColor)
+func (s Stream) IMReadCurrentColor() gocv.Mat {
+ return gocv.IMRead(s.GetCurrentColorInstantPath(), gocv.IMReadColor)
+}
+
// GetNextInstantPath returns filepath.Join(s.GetStreamDirPath(), s.Base64, "last.jpg")
func (s Stream) GetNextInstantPath() string {
return filepath.Join(s.GetStreamStoreDirPath(), "last.jpg")
diff --git a/templates/stream.html b/templates/stream.html
index aa28283..d34640d 100755
--- a/templates/stream.html
+++ b/templates/stream.html
@@ -1,4 +1,6 @@
{{template "base" .}}
{{define "content"}}
+
+
{{end}}
\ No newline at end of file