moved some more stuff to the Stream struct

This commit is contained in:
BroodjeAap 2020-07-07 18:13:41 +00:00
parent bf1f49302e
commit 2086989d58
2 changed files with 41 additions and 6 deletions

10
main.go
View file

@ -45,20 +45,18 @@ func stream(w http.ResponseWriter, r *http.Request) {
go stream.SaveStreamInstant(URL, img) go stream.SaveStreamInstant(URL, img)
if FileExists(stream.GetPreviousInstantPath()) { if stream.PreviousInstantPathExists() {
newMat := gocv.NewMat() newMat := gocv.NewMat()
mat, err := gocv.IMDecode(img, gocv.IMReadColor) mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
if err != nil { if err != nil {
log.Fatal("Could not IMDecode img") log.Fatal("Could not IMDecode img")
} }
gocv.CvtColor(mat, &newMat, gocv.ColorBGRToGray) gocv.GaussianBlur(mat, &newMat, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
gocv.GaussianBlur(newMat, &newMat, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
previous := gocv.IMRead(stream.GetPreviousInstantPath(), gocv.IMReadColor) previous := stream.IMReadPrevious()
gocv.CvtColor(previous, &previous, gocv.ColorBGRToGray)
gocv.GaussianBlur(previous, &previous, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect) gocv.GaussianBlur(previous, &previous, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
gocv.AbsDiff(previous, newMat, &newMat) gocv.AbsDiff(previous, newMat, &newMat)

View file

@ -6,6 +6,8 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"gocv.io/x/gocv"
) )
// Stream Unexported // Stream Unexported
@ -70,17 +72,52 @@ func (s Stream) GetStreamDirPath() string {
return filepath.Join(".", "streams") return filepath.Join(".", "streams")
} }
// StreamStorePathExists returns FileExists(GetStreamDirPath())
func (s Stream) StreamStorePathExists() bool {
return FileExists(s.GetStreamDirPath())
}
// GetPreviousInstantPath returns filepath.Join(GetStreamDirPath(), s.base64, "previous.jpg") // GetPreviousInstantPath returns filepath.Join(GetStreamDirPath(), s.base64, "previous.jpg")
func (s Stream) GetPreviousInstantPath() string { func (s Stream) GetPreviousInstantPath() string {
return filepath.Join(s.GetStreamDirPath(), s.base64, "previous.jpg") return filepath.Join(s.GetStreamDirPath(), s.base64, "previous.jpg")
} }
// PreviousInstantPathExists returns FileExists(GetPreviousInstantPath())
func (s Stream) PreviousInstantPathExists() bool {
return FileExists(s.GetPreviousInstantPath())
}
// IMReadPrevious returns gocv.IMRead(GetPreviousInstantPath(), gocv.IMReadGrayScale)
func (s Stream) IMReadPrevious() gocv.Mat {
return gocv.IMRead(s.GetPreviousInstantPath(), gocv.IMReadGrayScale)
}
// GetCurrentInstantPath returns filepath.Join(s.GetStreamDirPath(), s.base64, "current.jpg") // GetCurrentInstantPath returns filepath.Join(s.GetStreamDirPath(), s.base64, "current.jpg")
func (s Stream) GetCurrentInstantPath() string { func (s Stream) GetCurrentInstantPath() string {
return filepath.Join(s.GetStreamDirPath(), s.base64, "current.jpg") return filepath.Join(s.GetStreamDirPath(), s.base64, "current.jpg")
} }
// CurrentInstantPathExists returns FileExists(GetCurrentInstantPath())
func (s Stream) CurrentInstantPathExists() bool {
return FileExists(s.GetCurrentInstantPath())
}
// IMReadCurrent returns gocv.IMRead(GetCurrentInstantPath(), gocv.IMReadGrayScale)
func (s Stream) IMReadCurrent() gocv.Mat {
return gocv.IMRead(s.GetCurrentInstantPath(), gocv.IMReadGrayScale)
}
// GetLastInstantPath returns filepath.Join(s.GetStreamDirPath(), s.base64, "last.jpg") // GetLastInstantPath returns filepath.Join(s.GetStreamDirPath(), s.base64, "last.jpg")
func (s Stream) GetLastInstantPath() string { func (s Stream) GetLastInstantPath() string {
return filepath.Join(s.GetStreamDirPath(), s.base64, "last.jpg") return filepath.Join(s.GetStreamDirPath(), s.base64, "last.jpg")
} }
// LastInstantPathExists returns FileExists(GetLastInstantPath())
func (s Stream) LastInstantPathExists() bool {
return FileExists(s.GetLastInstantPath())
}
// IMReadLast returns gocv.IMRead(GetLastInstantPath(), gocv.IMReadGrayScale)
func (s Stream) IMReadLast() gocv.Mat {
return gocv.IMRead(s.GetLastInstantPath(), gocv.IMReadGrayScale)
}