refactored to single area per WatchArea
This commit is contained in:
parent
eb11a50d08
commit
1a4f3e8227
4 changed files with 62 additions and 62 deletions
59
stream.go
59
stream.go
|
@ -17,12 +17,12 @@ import (
|
|||
|
||||
// Stream represents a stream to monitor
|
||||
type Stream struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
Base64 string `json:"base64"`
|
||||
Interval int `json:"interval"`
|
||||
Watches []Watch `json:"watches"`
|
||||
FileLock sync.Mutex `json:"lock"`
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
Base64 string `json:"base64"`
|
||||
Interval int `json:"interval"`
|
||||
WatchAreas []WatchArea `json:"watchAreas"`
|
||||
FileLock sync.Mutex `json:"lock"`
|
||||
}
|
||||
|
||||
// NewStream creates a new Stream Object
|
||||
|
@ -30,39 +30,29 @@ func NewStream(Name string, URL string) Stream {
|
|||
base64 := URLToBase64(URL)
|
||||
|
||||
stream := Stream{
|
||||
Name: Name,
|
||||
URL: URL,
|
||||
Base64: base64,
|
||||
Interval: 5000,
|
||||
Watches: make([]Watch, 0),
|
||||
Name: Name,
|
||||
URL: URL,
|
||||
Base64: base64,
|
||||
Interval: 5000,
|
||||
WatchAreas: make([]WatchArea, 0),
|
||||
}
|
||||
stream.Watches = append(stream.Watches,
|
||||
Watch{
|
||||
stream.WatchAreas = append(stream.WatchAreas,
|
||||
WatchArea{
|
||||
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),
|
||||
},
|
||||
Area: image.Rect(30, 30, 400, 200),
|
||||
},
|
||||
Watch{
|
||||
WatchArea{
|
||||
Name: "test2",
|
||||
Color: color.RGBA{0, 255, 255, 255},
|
||||
Areas: []image.Rectangle{
|
||||
image.Rect(800, 30, 1000, 500),
|
||||
image.Rect(700, 500, 1200, 700),
|
||||
},
|
||||
Area: image.Rect(800, 30, 1000, 500),
|
||||
},
|
||||
Watch{
|
||||
WatchArea{
|
||||
Name: "test3",
|
||||
Color: color.RGBA{255, 255, 0, 255},
|
||||
Areas: []image.Rectangle{
|
||||
image.Rect(50, 400, 450, 700),
|
||||
},
|
||||
Area: image.Rect(50, 400, 450, 700),
|
||||
},
|
||||
)
|
||||
log.Println("TEST")
|
||||
stream.WriteStreamJSON()
|
||||
return stream
|
||||
}
|
||||
|
@ -105,15 +95,10 @@ func (s Stream) Update() {
|
|||
gocv.CvtColor(debug, &debug, gocv.ColorGrayToBGRA)
|
||||
|
||||
contours := gocv.FindContours(diff, gocv.RetrievalExternal, gocv.ChainApproxSimple)
|
||||
for _, watch := range s.Watches {
|
||||
skipNextAreas := true // Still draw all area rectangles
|
||||
for _, area := range watch.Areas {
|
||||
gocv.Rectangle(&debug, area, watch.Color, 10)
|
||||
if skipNextAreas && s.CheckWatchAreas(area, contours) {
|
||||
go watch.CopyInstant(s.GetCurrentColorInstantPath(), s)
|
||||
skipNextAreas = false
|
||||
break
|
||||
}
|
||||
for _, watchArea := range s.WatchAreas {
|
||||
gocv.Rectangle(&debug, watchArea.Area, watchArea.Color, 10)
|
||||
if s.CheckWatchAreas(watchArea.Area, contours) {
|
||||
go watchArea.CopyInstant(s.GetCurrentColorInstantPath(), s)
|
||||
}
|
||||
}
|
||||
go gocv.IMWrite(s.GetDebugInstantPath(), debug)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<tr>
|
||||
<td>{{ $stream.Name }}</td>
|
||||
<td>{{ $stream.URL }} </td>
|
||||
<td>{{ len $stream.Watches }} </td>
|
||||
<td>{{ len $stream.WatchAreas }} </td>
|
||||
<td>{{ $stream.Interval }}</td>
|
||||
<td><a href="/?name={{ $stream.Name }}">Go</a></td>
|
||||
</tr>
|
||||
|
|
|
@ -12,15 +12,30 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Color</th>
|
||||
<th>Areas</th>
|
||||
<th colspan="3">Color</th>
|
||||
<th colspan="4">Area</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>R</th>
|
||||
<th>G</th>
|
||||
<th>B</th>
|
||||
<th>MinX</th>
|
||||
<th>MinY</th>
|
||||
<th>MaxX</th>
|
||||
<th>MaxY</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{{range $watch := .Watches}}
|
||||
{{range $watchArea := .WatchAreas}}
|
||||
<tr>
|
||||
<td>{{ $watch.Name }}</td>
|
||||
<td>{{ $watch.Color }}</td>
|
||||
<td>{{ len $watch.Areas }}</td>
|
||||
<td>{{ $watchArea.Name }}</td>
|
||||
<td>{{ $watchArea.Color.R }}</td>
|
||||
<td>{{ $watchArea.Color.G }}</td>
|
||||
<td>{{ $watchArea.Color.B }}</td>
|
||||
<td>{{ $watchArea.Area.Min.X }}</td>
|
||||
<td>{{ $watchArea.Area.Min.Y }}</td>
|
||||
<td>{{ $watchArea.Area.Max.X }}</td>
|
||||
<td>{{ $watchArea.Area.Max.Y }}</td>
|
||||
</tr>
|
||||
|
||||
{{end}}
|
||||
|
|
36
watch.go
36
watch.go
|
@ -12,35 +12,35 @@ import (
|
|||
|
||||
const timeLayout = "2006-01-02_15-4-5.jpg"
|
||||
|
||||
// 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"`
|
||||
// WatchArea defines one or more areas that should be monitored for motion
|
||||
type WatchArea struct {
|
||||
Name string `json:"name"`
|
||||
Color color.RGBA `json:"color"`
|
||||
Area image.Rectangle `json:"area"`
|
||||
}
|
||||
|
||||
// WatchStoreDirExists returns filepath.Join(s.GetStreamStoreDirPath(), w.Name)
|
||||
func (w Watch) WatchStoreDirExists(s Stream) bool {
|
||||
return FileExists(w.GetWatchStoreDir(s))
|
||||
// WatchAreaStoreDirExists returns filepath.Join(s.GetStreamStoreDirPath(), w.Name)
|
||||
func (w WatchArea) WatchAreaStoreDirExists(s Stream) bool {
|
||||
return FileExists(w.GetWatchAreaStoreDir(s))
|
||||
}
|
||||
|
||||
// GetWatchStoreDir returns filepath.Join(s.GetStreamStoreDirPath(), w.Name)
|
||||
func (w Watch) GetWatchStoreDir(s Stream) string {
|
||||
// GetWatchAreaStoreDir returns filepath.Join(s.GetStreamStoreDirPath(), w.Name)
|
||||
func (w WatchArea) GetWatchAreaStoreDir(s Stream) string {
|
||||
return filepath.Join(s.GetStreamStoreDirPath(), w.Name)
|
||||
}
|
||||
|
||||
// GetWatchStoreDirInstantPath returns filepath.Join(s.GetWatchStoreDir(), "")
|
||||
func (w Watch) GetWatchStoreDirInstantPath(s Stream) string {
|
||||
// GetWatchAreaStoreDirInstantPath returns filepath.Join(s.GetWatchAreaStoreDir(), "")
|
||||
func (w WatchArea) GetWatchAreaStoreDirInstantPath(s Stream) string {
|
||||
now := time.Now()
|
||||
return filepath.Join(w.GetWatchStoreDir(s), now.Format(timeLayout))
|
||||
return filepath.Join(w.GetWatchAreaStoreDir(s), now.Format(timeLayout))
|
||||
}
|
||||
|
||||
// CopyInstant makes a copy of src to GetWatchStoreDirInstantPath(s)
|
||||
func (w Watch) CopyInstant(src string, s Stream) {
|
||||
if !FileExists(w.GetWatchStoreDir(s)) {
|
||||
os.MkdirAll(w.GetWatchStoreDir(s), os.ModePerm)
|
||||
// CopyInstant makes a copy of src to GetWatchAreaStoreDirInstantPath(s)
|
||||
func (w WatchArea) CopyInstant(src string, s Stream) {
|
||||
if !FileExists(w.GetWatchAreaStoreDir(s)) {
|
||||
os.MkdirAll(w.GetWatchAreaStoreDir(s), os.ModePerm)
|
||||
}
|
||||
dest := w.GetWatchStoreDirInstantPath(s)
|
||||
dest := w.GetWatchAreaStoreDirInstantPath(s)
|
||||
if !FileExists(src) {
|
||||
log.Fatal("Nothing to copy ", src)
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue