GetStreamInstant returns a Mat now
This commit is contained in:
parent
eb8b0d4d61
commit
4a196a21b2
2 changed files with 21 additions and 19 deletions
30
main.go
30
main.go
|
@ -54,34 +54,30 @@ func (server Server) stream(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
img := stream.GetStreamInstant()
|
||||
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
|
||||
if err != nil {
|
||||
log.Fatal("Could not IMDecode img")
|
||||
}
|
||||
mat := stream.GetStreamInstant()
|
||||
|
||||
//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)
|
||||
diff := gocv.NewMat()
|
||||
mat.CopyTo(&diff)
|
||||
gocv.CvtColor(diff, &diff, gocv.ColorBGRAToGray)
|
||||
gocv.GaussianBlur(diff, &diff, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
|
||||
|
||||
go stream.SaveStreamInstant(URL, mat)
|
||||
|
||||
if stream.PreviousInstantPathExists() {
|
||||
if err != nil {
|
||||
log.Fatal("Could not IMDecode img")
|
||||
}
|
||||
|
||||
previous := stream.IMReadPrevious()
|
||||
|
||||
gocv.GaussianBlur(previous, &previous, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
|
||||
|
||||
gocv.AbsDiff(previous, mat, &mat)
|
||||
gocv.AbsDiff(previous, diff, &diff)
|
||||
|
||||
gocv.Threshold(mat, &mat, 25, 255, gocv.ThresholdBinary)
|
||||
|
||||
//img, err = gocv.IMEncode(".jpg", newMat)
|
||||
gocv.Threshold(diff, &diff, 25, 255, gocv.ThresholdBinary)
|
||||
}
|
||||
|
||||
w.Write(img)
|
||||
jpg, err := gocv.IMEncode(".jpg", mat)
|
||||
if err != nil {
|
||||
log.Fatal("Could not encode Mat to jpg:", URL)
|
||||
}
|
||||
w.Write(jpg)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -105,7 +101,7 @@ func main() {
|
|||
stream := Stream{}
|
||||
json.Unmarshal([]byte(streamJSONFile), &stream)
|
||||
server.Streams[stream.URL] = stream
|
||||
go stream.Update()
|
||||
go stream.UpdateInterval()
|
||||
}
|
||||
|
||||
http.HandleFunc("/", server.index)
|
||||
|
|
10
stream.go
10
stream.go
|
@ -46,14 +46,20 @@ func (s Stream) UpdateInterval() {
|
|||
}
|
||||
|
||||
// GetStreamInstant http.Get(URL) and returns the response
|
||||
func (s Stream) GetStreamInstant() []byte {
|
||||
func (s Stream) GetStreamInstant() gocv.Mat {
|
||||
resp, err := http.Get(s.URL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
img, err := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
return img
|
||||
|
||||
mat, err := gocv.IMDecode(img, gocv.IMReadColor)
|
||||
if err != nil {
|
||||
log.Fatal("Could not IMDecode img")
|
||||
}
|
||||
|
||||
return mat
|
||||
}
|
||||
|
||||
// SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath
|
||||
|
|
Loading…
Add table
Reference in a new issue