Skip to content

Commit f74db71

Browse files
committed
matchfuction: go to blobies instead of rects
1 parent 60c47f8 commit f74db71

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

blob/array_tracker.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package blob
22

33
import (
4-
"image"
54
"math"
65

76
uuid "github.com/satori/go.uuid"
@@ -35,14 +34,8 @@ func NewBlobiesDefaults() *Blobies {
3534
}
3635

3736
// MatchToExisting Check if some of blobs already exists
38-
func (bt *Blobies) MatchToExisting(rects []image.Rectangle) {
37+
func (bt *Blobies) MatchToExisting(blobies []*Blobie) {
3938
bt.prepare()
40-
blobies := make([]*Blobie, len(rects))
41-
for i := range blobies {
42-
blobies[i] = NewBlobie(rects[i], bt.maxPointsInTrack)
43-
blobies[i].drawingOptions = bt.DrawingOptions
44-
}
45-
4639
for i := range blobies {
4740
minUUID := uuid.UUID{}
4841
minDistance := math.MaxFloat64
@@ -61,10 +54,10 @@ func (bt *Blobies) MatchToExisting(rects []image.Rectangle) {
6154
bt.Register(blobies[i])
6255
}
6356
}
64-
6557
bt.RefreshNoMatch()
6658
}
6759

60+
// RefreshNoMatch - Refresh state of each blob
6861
func (bt *Blobies) RefreshNoMatch() {
6962
for i, b := range (*bt).Objects {
7063
if b.isExists == false {

blob/blob.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ type Blobie struct {
2323
noMatchTimes int
2424
PredictedNextPosition image.Point
2525

26+
classID int
27+
className string
28+
2629
// For array tracker
2730
drawingOptions *DrawOptions
2831
crossedLine bool
2932
}
3033

3134
// NewBlobie - Constructor for Blobie (default values)
32-
func NewBlobie(rect image.Rectangle, maxPointsInTrack int) *Blobie {
35+
func NewBlobie(rect image.Rectangle, maxPointsInTrack, classID int, className string) *Blobie {
3336
center := image.Pt((rect.Min.X*2+rect.Dx())/2, (rect.Min.Y*2+rect.Dy())/2)
3437
width := float64(rect.Dx())
3538
height := float64(rect.Dy())
@@ -45,6 +48,8 @@ func NewBlobie(rect image.Rectangle, maxPointsInTrack int) *Blobie {
4548
isStillBeingTracked: true,
4649
noMatchTimes: 0,
4750

51+
classID: classID,
52+
className: className,
4853
crossedLine: false,
4954
}
5055
}
@@ -70,10 +75,28 @@ func NewBlobieDefaults(rect image.Rectangle) *Blobie {
7075
isStillBeingTracked: true,
7176
noMatchTimes: 0,
7277

78+
classID: -1,
79+
className: "No class",
7380
crossedLine: false,
7481
}
7582
}
7683

84+
// SetClass - Set class information (eg. classID=1, className=vehicle)
85+
func (b *Blobie) SetClass(classID int, className string) {
86+
b.SetClassID(classID)
87+
b.SetClassName(className)
88+
}
89+
90+
// SetClassID - Set class identifier
91+
func (b *Blobie) SetClassID(classID int) {
92+
b.classID = classID
93+
}
94+
95+
// SetClassName - Set class name
96+
func (b *Blobie) SetClassName(className string) {
97+
b.className = className
98+
}
99+
77100
// Update - Update info about blob
78101
func (b *Blobie) Update(newb Blobie) {
79102
b.CurrentRect = newb.CurrentRect

0 commit comments

Comments
 (0)