Skip to content

Commit 6169a73

Browse files
committed
extend interface functions [v2]
1 parent f39e228 commit 6169a73

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

v2/blob/blob.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import (
88

99
type Blobie interface {
1010
GetCenter() image.Point
11+
GetCurrentRect() image.Rectange
1112
GetPredictedNextPosition() image.Point
1213
GetDiagonal() float64
14+
GetClassID() int
15+
GetClassName() string
1316
Exists() bool
1417
NoMatchTimes() int
1518
IncrementNoMatchTimes()
@@ -18,4 +21,6 @@ type Blobie interface {
1821
SetID(id uuid.UUID)
1922
PredictNextPosition(n int)
2023
Update(newb Blobie) error
24+
SetDraw(drawOptions *DrawOptions)
25+
DrawTrack(mat *gocv.Mat, optionalText string)
2126
}

v2/blob/kalman_blob.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func (sb *KalmanBlobie) GetCenter() image.Point {
146146
return sb.Center
147147
}
148148

149+
func (sb *KalmanBlobie) GetCurrentRect() image.Rectange {
150+
return sb.CurrentRect
151+
}
152+
149153
func (sb *KalmanBlobie) GetDiagonal() float64 {
150154
return sb.Diagonal
151155
}
@@ -177,3 +181,38 @@ func (sb *KalmanBlobie) IncrementNoMatchTimes() {
177181
func (sb *KalmanBlobie) SetExists(isExists bool) {
178182
sb.isExists = isExists
179183
}
184+
185+
// GetClassID Returns class identifier [KalmanBlobie]
186+
func (b *KalmanBlobie) GetClassID() int {
187+
return b.classID
188+
}
189+
190+
// GetClassName Returns class name [KalmanBlobie]
191+
func (b *KalmanBlobie) GetClassName() string {
192+
return b.className
193+
}
194+
195+
// SetDraw Sets options for drawing [KalmanBlobie]
196+
func (b *KalmanBlobie) SetDraw(drawOptions *DrawOptions) {
197+
b.drawingOptions = drawOptions
198+
}
199+
200+
// DrawTrack Draws blob's track [KalmanBlobie]
201+
func (b *KalmanBlobie) DrawTrack(mat *gocv.Mat, optionalText string) {
202+
if b.drawingOptions == nil {
203+
b.drawingOptions = NewDrawOptionsDefault()
204+
}
205+
gocv.Rectangle(mat, b.CurrentRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
206+
if b.isStillBeingTracked {
207+
for i := range b.Track {
208+
gocv.Circle(mat, b.Track[i], b.drawingOptions.CentroidColor.Radius, b.drawingOptions.CentroidColor.Color, b.drawingOptions.CentroidColor.Thickness)
209+
}
210+
if optionalText != "" {
211+
pt := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y)
212+
textSize := gocv.GetTextSize(optionalText, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Thickness)
213+
textRect := image.Rectangle{Min: image.Point{X: pt.X, Y: pt.Y - textSize.Y}, Max: image.Point{X: pt.X + textSize.X, Y: pt.Y}}
214+
gocv.Rectangle(mat, textRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
215+
gocv.PutText(mat, optionalText, pt, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Color, b.drawingOptions.TextColor.Thickness)
216+
}
217+
}
218+
}

v2/blob/simple_blob.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (sb *SimpleBlobie) GetCenter() image.Point {
3838
return sb.Center
3939
}
4040

41+
func (sb *SimpleBlobie) GetCurrentRect() image.Rectange {
42+
return sb.CurrentRect
43+
}
44+
4145
func (sb *SimpleBlobie) GetDiagonal() float64 {
4246
return sb.Diagonal
4347
}
@@ -138,17 +142,17 @@ func (b *SimpleBlobie) SetClassName(className string) {
138142
b.className = className
139143
}
140144

141-
// GetClassID - Return class identifier
145+
// GetClassID Returns class identifier [SimpleBlobie]
142146
func (b *SimpleBlobie) GetClassID() int {
143147
return b.classID
144148
}
145149

146-
// GetClassName - Return class name
150+
// GetClassName Returns class name [SimpleBlobie]
147151
func (b *SimpleBlobie) GetClassName() string {
148152
return b.className
149153
}
150154

151-
// SetDraw - Set options for drawing
155+
// SetDraw Sets options for drawing [SimpleBlobie]
152156
func (b *SimpleBlobie) SetDraw(drawOptions *DrawOptions) {
153157
b.drawingOptions = drawOptions
154158
}
@@ -209,7 +213,7 @@ func (b *SimpleBlobie) PredictNextPosition(n int) {
209213
(*b).PredictedNextPosition.Y = (*b).Track[len((*b).Track)-1].Y + deltaY
210214
}
211215

212-
// DrawTrack - Draw blob's track
216+
// DrawTrack Draws blob's track [SimpleBlobie]
213217
func (b *SimpleBlobie) DrawTrack(mat *gocv.Mat, optionalText string) {
214218
if b.drawingOptions == nil {
215219
b.drawingOptions = NewDrawOptionsDefault()

0 commit comments

Comments
 (0)