From 62ac74c782451240ab4d625a5361ba1583143bfb Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Tue, 18 Aug 2020 19:02:41 +0000 Subject: [PATCH] added some more comments to stream.go --- stream.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stream.go b/stream.go index 28ba4ba..05a2529 100755 --- a/stream.go +++ b/stream.go @@ -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 {