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),
}
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)
}