diff --git a/stream.go b/stream.go index aaab6d2..2c48de3 100755 --- a/stream.go +++ b/stream.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "image" + "image/color" "io/ioutil" "log" "net/http" @@ -63,8 +64,32 @@ func (s Stream) Update() { diff := gocv.NewMat() previousGrey := s.IMReadPrevious() gocv.AbsDiff(previousGrey, currentGrey, &diff) - gocv.Threshold(diff, &diff, 50, 255, gocv.ThresholdBinary) - go gocv.IMWrite(s.GetDebugInstantPath(), diff) + gocv.Threshold(diff, &diff, 100, 255, gocv.ThresholdBinary) + + dilateKernel := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(20, 20)) + gocv.Dilate(diff, &diff, dilateKernel) + + debug := gocv.NewMat() + diff.CopyTo(&debug) + gocv.CvtColor(debug, &debug, gocv.ColorGrayToBGRA) + + area := image.Rectangle{ + Min: image.Point{X: 50, Y: 50}, + Max: image.Point{X: 300, Y: 300}, + } + + gocv.Rectangle(&debug, area, color.RGBA{255, 0, 255, 255}, 10) + + contours := gocv.FindContours(diff, gocv.RetrievalExternal, gocv.ChainApproxSimple) + for i, contour := range contours { + for _, point := range contour { + if point.In(area) { + gocv.DrawContours(&debug, contours, i, color.RGBA{50, 250, 50, 150}, 5) + } + } + } + + go gocv.IMWrite(s.GetDebugInstantPath(), debug) } // UpdateInterval calls Update() every interval