added some more comments to stream.go
This commit is contained in:
parent
31aaa3db30
commit
62ac74c782
1 changed files with 5 additions and 2 deletions
|
|
@ -59,13 +59,14 @@ func (s *Stream) Update() {
|
|||
resp, err := http.Get(s.URL)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
s.Timeouts++
|
||||
s.Timeouts++ // For increasing the Interval time every timeout
|
||||
return
|
||||
}
|
||||
s.Timeouts = 0
|
||||
img, err := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Get the image from the response and write it to disk in a goroutine
|
||||
mat, err := gocv.IMDecode(img, gocv.IMReadColor)
|
||||
if err != nil {
|
||||
log.Println("Could not IMDecode img", err)
|
||||
|
|
@ -73,6 +74,7 @@ func (s *Stream) Update() {
|
|||
}
|
||||
go gocv.IMWrite(s.GetCurrentColorInstantPath(), mat)
|
||||
|
||||
// Turn the current image into greyscale and also write that to disk in a goroutine
|
||||
currentGrey := gocv.NewMat()
|
||||
gocv.CvtColor(mat, ¤tGrey, gocv.ColorBGRAToGray)
|
||||
gocv.GaussianBlur(currentGrey, ¤tGrey, image.Point{X: 21, Y: 21}, 0, 0, gocv.BorderReflect)
|
||||
|
|
@ -81,7 +83,7 @@ func (s *Stream) Update() {
|
|||
if !s.PreviousInstantPathExists() {
|
||||
return
|
||||
}
|
||||
|
||||
// If there is a previous image saved to disk, calculate the difference between the two and amplify those differences
|
||||
diff := gocv.NewMat()
|
||||
previousGrey := s.IMReadPrevious()
|
||||
gocv.AbsDiff(previousGrey, currentGrey, &diff)
|
||||
|
|
@ -94,6 +96,7 @@ func (s *Stream) Update() {
|
|||
diff.CopyTo(&debug)
|
||||
gocv.CvtColor(debug, &debug, gocv.ColorGrayToBGRA)
|
||||
|
||||
// Get the contours and check if they are in any of the WatchAreas
|
||||
contours := gocv.FindContours(diff, gocv.RetrievalExternal, gocv.ChainApproxSimple)
|
||||
s.MotionDetected = false
|
||||
for _, watchArea := range s.WatchAreas {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue