moved areas to a seperate Watch struct
This commit is contained in:
parent
1582a4714d
commit
f4099dc4f5
2 changed files with 37 additions and 17 deletions
41
stream.go
41
stream.go
|
@ -15,13 +15,13 @@ import (
|
|||
"gocv.io/x/gocv"
|
||||
)
|
||||
|
||||
// Stream Unexported
|
||||
// Stream represents a stream to monitor
|
||||
type Stream struct {
|
||||
URL string `json:"url"`
|
||||
Base64 string `json:"base64"`
|
||||
Interval int `json:"interval"`
|
||||
Areas map[string][]image.Rectangle `json:"areas"`
|
||||
FileLock sync.Mutex `json:"lock"`
|
||||
URL string `json:"url"`
|
||||
Base64 string `json:"base64"`
|
||||
Interval int `json:"interval"`
|
||||
Watches []Watch `json:"watches"`
|
||||
FileLock sync.Mutex `json:"lock"`
|
||||
}
|
||||
|
||||
// NewStream creates a new Stream Object
|
||||
|
@ -32,13 +32,20 @@ func NewStream(URL string) Stream {
|
|||
URL: URL,
|
||||
Base64: base64,
|
||||
Interval: 5000,
|
||||
Areas: make(map[string][]image.Rectangle),
|
||||
Watches: make([]Watch, 0),
|
||||
}
|
||||
rectList := make([]image.Rectangle, 0)
|
||||
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
|
||||
watch := Watch{
|
||||
Name: "test",
|
||||
Color: color.RGBA{255, 0, 255, 255},
|
||||
Areas: []image.Rectangle{
|
||||
image.Rect(30, 30, 400, 200),
|
||||
image.Rect(400, 30, 500, 200),
|
||||
image.Rect(400, 200, 500, 500),
|
||||
},
|
||||
}
|
||||
log.Println(watch)
|
||||
stream.Watches = append(stream.Watches, watch)
|
||||
log.Println(stream)
|
||||
stream.WriteStreamJSON()
|
||||
return stream
|
||||
}
|
||||
|
@ -82,9 +89,9 @@ func (s Stream) Update() {
|
|||
|
||||
contours := gocv.FindContours(diff, gocv.RetrievalExternal, gocv.ChainApproxSimple)
|
||||
|
||||
for _, areas := range s.Areas {
|
||||
for _, area := range areas {
|
||||
gocv.Rectangle(&debug, area, color.RGBA{255, 0, 255, 255}, 10)
|
||||
for _, watch := range s.Watches {
|
||||
for _, area := range watch.Areas {
|
||||
gocv.Rectangle(&debug, area, watch.Color, 10)
|
||||
for contourIndex, contour := range contours {
|
||||
for _, point := range contour {
|
||||
|
||||
|
@ -104,7 +111,7 @@ func (s Stream) Update() {
|
|||
// UpdateInterval calls Update() every interval
|
||||
func (s Stream) UpdateInterval() {
|
||||
for {
|
||||
s.Update()
|
||||
go s.Update()
|
||||
time.Sleep(time.Duration(s.Interval) * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +176,7 @@ func (s Stream) WriteStreamJSON() {
|
|||
if !FileExists(s.GetStreamStoreDirPath()) {
|
||||
os.MkdirAll(s.GetStreamStoreDirPath(), os.ModePerm)
|
||||
}
|
||||
file, _ := json.MarshalIndent(s, "", "")
|
||||
file, _ := json.MarshalIndent(s, "", "\t")
|
||||
_ = ioutil.WriteFile(s.GetStreamJSONPath(), file, 0644)
|
||||
}
|
||||
|
||||
|
|
13
watch.go
Executable file
13
watch.go
Executable file
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
// Watch defines one or more areas that should be monitored for motion
|
||||
type Watch struct {
|
||||
Name string `json:"name"`
|
||||
Color color.RGBA `json:"color"`
|
||||
Areas []image.Rectangle `json:"areas"`
|
||||
}
|
Loading…
Add table
Reference in a new issue