diff --git a/main.go b/main.go index 4adebb4..787529f 100755 --- a/main.go +++ b/main.go @@ -45,20 +45,18 @@ func stream(w http.ResponseWriter, r *http.Request) { go stream.SaveStreamInstant(URL, img) - if FileExists(stream.GetPreviousInstantPath()) { + if stream.PreviousInstantPathExists() { newMat := gocv.NewMat() - mat, err := gocv.IMDecode(img, gocv.IMReadColor) + mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale) if err != nil { log.Fatal("Could not IMDecode img") } - gocv.CvtColor(mat, &newMat, gocv.ColorBGRToGray) - gocv.GaussianBlur(newMat, &newMat, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect) + gocv.GaussianBlur(mat, &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.AbsDiff(previous, newMat, &newMat) diff --git a/stream.go b/stream.go index 7d28d85..e06d342 100755 --- a/stream.go +++ b/stream.go @@ -6,6 +6,8 @@ import ( "net/http" "os" "path/filepath" + + "gocv.io/x/gocv" ) // Stream Unexported @@ -70,17 +72,52 @@ func (s Stream) GetStreamDirPath() string { 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") func (s Stream) GetPreviousInstantPath() string { 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") func (s Stream) GetCurrentInstantPath() string { 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") func (s Stream) GetLastInstantPath() string { 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) +}