added debug endpoint that gets a debug.jpg
This commit is contained in:
parent
dd86398394
commit
0d7faa4397
3 changed files with 41 additions and 1 deletions
23
main.go
23
main.go
|
@ -108,6 +108,28 @@ func (server Server) currentColor(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write(jpg)
|
||||
}
|
||||
|
||||
func (server Server) debug(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.DebugInstantPathExists() {
|
||||
log.Println(stream.GetDebugInstantPath())
|
||||
return
|
||||
}
|
||||
jpg, err := gocv.IMEncode(".jpg", stream.IMReadDebug())
|
||||
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
|
||||
|
@ -158,5 +180,6 @@ func main() {
|
|||
http.HandleFunc("/previous", server.previous)
|
||||
http.HandleFunc("/current_color", server.currentColor)
|
||||
http.HandleFunc("/current", server.current)
|
||||
http.HandleFunc("/debug", server.debug)
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
|
18
stream.go
18
stream.go
|
@ -63,7 +63,8 @@ func (s Stream) Update() {
|
|||
diff := gocv.NewMat()
|
||||
previousGrey := s.IMReadPrevious()
|
||||
gocv.AbsDiff(previousGrey, currentGrey, &diff)
|
||||
gocv.Threshold(diff, &diff, 10, 255, gocv.ThresholdBinary)
|
||||
gocv.Threshold(diff, &diff, 50, 255, gocv.ThresholdBinary)
|
||||
go gocv.IMWrite(s.GetDebugInstantPath(), diff)
|
||||
}
|
||||
|
||||
// UpdateInterval calls Update() every interval
|
||||
|
@ -202,3 +203,18 @@ func (s Stream) NextInstantPathExists() bool {
|
|||
func (s Stream) IMReadNext() gocv.Mat {
|
||||
return gocv.IMRead(s.GetNextInstantPath(), gocv.IMReadGrayScale)
|
||||
}
|
||||
|
||||
// GetDebugInstantPath returns filepath.Join(s.GetStreamDirPath(), s.Base64, "debug.jpg")
|
||||
func (s Stream) GetDebugInstantPath() string {
|
||||
return filepath.Join(s.GetStreamStoreDirPath(), "debug.jpg")
|
||||
}
|
||||
|
||||
// DebugInstantPathExists returns FileExists(GetDebugInstantPath())
|
||||
func (s Stream) DebugInstantPathExists() bool {
|
||||
return FileExists(s.GetDebugInstantPath())
|
||||
}
|
||||
|
||||
// IMReadDebug returns gocv.IMRead(GetDebugInstantPath(), gocv.IMReadGrayScale)
|
||||
func (s Stream) IMReadDebug() gocv.Mat {
|
||||
return gocv.IMRead(s.GetDebugInstantPath(), gocv.IMReadGrayScale)
|
||||
}
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
{{define "content"}}
|
||||
<img src="/stream?URL={{.URL}}">
|
||||
<img src="/previous?URL={{.URL}}">
|
||||
<img src="/debug?URL={{.URL}}">
|
||||
<img src="/current?URL={{.URL}}">
|
||||
{{end}}
|
Loading…
Add table
Reference in a new issue