more cleanup
This commit is contained in:
parent
93f416403e
commit
79c7e03620
2 changed files with 22 additions and 19 deletions
20
main.go
20
main.go
|
@ -42,28 +42,30 @@ func stream(w http.ResponseWriter, r *http.Request) {
|
|||
stream := NewStream(URL)
|
||||
|
||||
img := stream.GetStreamInstant(URL)
|
||||
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
|
||||
if err != nil {
|
||||
log.Fatal("Could not IMDecode img")
|
||||
}
|
||||
|
||||
go stream.SaveStreamInstant(URL, img)
|
||||
//gocv.Resize(mat, &mat, image.Point{X: 0, Y: 0}, 0, 0, gocv.InterpolationCubic)
|
||||
gocv.GaussianBlur(mat, &mat, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
|
||||
|
||||
go stream.SaveStreamInstant(URL, mat)
|
||||
|
||||
if stream.PreviousInstantPathExists() {
|
||||
newMat := gocv.NewMat()
|
||||
|
||||
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
|
||||
if err != nil {
|
||||
log.Fatal("Could not IMDecode img")
|
||||
}
|
||||
|
||||
gocv.GaussianBlur(mat, &newMat, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
|
||||
|
||||
previous := stream.IMReadPrevious()
|
||||
|
||||
gocv.GaussianBlur(previous, &previous, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
|
||||
|
||||
gocv.AbsDiff(previous, newMat, &newMat)
|
||||
gocv.AbsDiff(previous, mat, &mat)
|
||||
|
||||
gocv.Threshold(newMat, &newMat, 25, 255, gocv.ThresholdBinary)
|
||||
gocv.Threshold(mat, &mat, 25, 255, gocv.ThresholdBinary)
|
||||
|
||||
img, err = gocv.IMEncode(".jpg", newMat)
|
||||
//img, err = gocv.IMEncode(".jpg", newMat)
|
||||
}
|
||||
|
||||
w.Write(img)
|
||||
|
|
21
stream.go
21
stream.go
|
@ -40,22 +40,18 @@ func (s Stream) GetStreamInstant(URL string) []byte {
|
|||
}
|
||||
|
||||
// SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath
|
||||
func (s Stream) SaveStreamInstant(URL string, img []byte) {
|
||||
streamDir := URLToBase64(URL)
|
||||
streamStoreDir := filepath.Join(".", "streams", string(streamDir))
|
||||
func (s Stream) SaveStreamInstant(URL string, mat gocv.Mat) {
|
||||
streamStoreDir := s.GetStreamStoreDirPath()
|
||||
os.MkdirAll(streamStoreDir, os.ModePerm)
|
||||
|
||||
currentStreamInstantPath := filepath.Join(streamStoreDir, "current.jpg")
|
||||
swap := FileExists(streamStoreDir)
|
||||
currentStreamInstantPath := s.GetCurrentInstantPath()
|
||||
swap := FileExists(s.GetCurrentInstantPath())
|
||||
|
||||
if swap {
|
||||
currentStreamInstantPath = filepath.Join(streamStoreDir, "next.jpg")
|
||||
currentStreamInstantPath = s.GetNextInstantPath()
|
||||
}
|
||||
|
||||
err := ioutil.WriteFile(currentStreamInstantPath, img, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Fatal("Can't write latest stream instant.")
|
||||
}
|
||||
gocv.IMWrite(currentStreamInstantPath, mat)
|
||||
|
||||
if swap {
|
||||
s.SwapInstants(s.GetPreviousInstantPath(), s.GetCurrentInstantPath(), s.GetNextInstantPath())
|
||||
|
@ -84,6 +80,11 @@ func (s Stream) StreamStorePathExists() bool {
|
|||
return FileExists(s.GetStreamDirPath())
|
||||
}
|
||||
|
||||
// GetStreamStoreDirPath returns filepath.Join(s.GetStreamDirPath(), s.base64)
|
||||
func (s Stream) GetStreamStoreDirPath() string {
|
||||
return filepath.Join(s.GetStreamDirPath(), s.base64)
|
||||
}
|
||||
|
||||
// GetPreviousInstantPath returns filepath.Join(GetStreamDirPath(), s.base64, "previous.jpg")
|
||||
func (s Stream) GetPreviousInstantPath() string {
|
||||
return filepath.Join(s.GetStreamDirPath(), s.base64, "previous.jpg")
|
||||
|
|
Loading…
Add table
Reference in a new issue