added motion detection in areas, move to Area structs probably

This commit is contained in:
BroodjeAap 2020-07-11 14:38:17 +00:00
parent 308b966119
commit 30d693d0fe
2 changed files with 17 additions and 24 deletions

0
main.go Normal file → Executable file
View file

View file

@ -35,18 +35,9 @@ func NewStream(URL string) Stream {
Areas: make(map[string][]image.Rectangle), Areas: make(map[string][]image.Rectangle),
} }
rectList := make([]image.Rectangle, 0) rectList := make([]image.Rectangle, 0)
rectList = append(rectList, image.Rectangle{ rectList = append(rectList, image.Rect(30, 30, 400, 200))
Min: image.Point{X: 30, Y: 30}, rectList = append(rectList, image.Rect(400, 30, 500, 200))
Max: image.Point{X: 400, Y: 200}, rectList = append(rectList, image.Rect(400, 200, 500, 500))
})
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},
})
stream.Areas["test"] = rectList stream.Areas["test"] = rectList
stream.WriteStreamJSON() stream.WriteStreamJSON()
return stream return stream
@ -89,22 +80,24 @@ func (s Stream) Update() {
diff.CopyTo(&debug) diff.CopyTo(&debug)
gocv.CvtColor(debug, &debug, gocv.ColorGrayToBGRA) 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) contours := gocv.FindContours(diff, gocv.RetrievalExternal, gocv.ChainApproxSimple)
for i, contour := range contours {
for _, point := range contour { for _, areas := range s.Areas {
if point.In(area) { for _, area := range areas {
gocv.DrawContours(&debug, contours, i, color.RGBA{50, 250, 50, 150}, 5) 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) go gocv.IMWrite(s.GetDebugInstantPath(), debug)
} }