diff --git a/main.go b/main.go old mode 100644 new mode 100755 diff --git a/stream.go b/stream.go index 3258d28..58f3ce2 100755 --- a/stream.go +++ b/stream.go @@ -35,18 +35,9 @@ func NewStream(URL string) Stream { Areas: make(map[string][]image.Rectangle), } rectList := make([]image.Rectangle, 0) - rectList = append(rectList, image.Rectangle{ - Min: image.Point{X: 30, Y: 30}, - Max: image.Point{X: 400, Y: 200}, - }) - rectList = append(rectList, image.Rectangle{ - Min: image.Point{X: 500, Y: 30}, - Max: image.Point{X: 400, Y: 200}, - }) - rectList = append(rectList, image.Rectangle{ - Min: image.Point{X: 500, Y: 500}, - Max: image.Point{X: 400, Y: 200}, - }) + rectList = append(rectList, image.Rect(30, 30, 400, 200)) + rectList = append(rectList, image.Rect(400, 30, 500, 200)) + rectList = append(rectList, image.Rect(400, 200, 500, 500)) stream.Areas["test"] = rectList stream.WriteStreamJSON() return stream @@ -89,22 +80,24 @@ func (s Stream) Update() { 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) + + for _, areas := range s.Areas { + for _, area := range areas { + gocv.Rectangle(&debug, area, color.RGBA{255, 0, 255, 255}, 10) + for contourIndex, contour := range contours { + for _, point := range contour { + + if point.In(area) { + gocv.DrawContours(&debug, contours, contourIndex, color.RGBA{50, 250, 50, 150}, 5) + break + } else { + //log.Println("Outside area") + } + } } } } - go gocv.IMWrite(s.GetDebugInstantPath(), debug) }