Skip to content

Commit

Permalink
change DrawTrack method
Browse files Browse the repository at this point in the history
  • Loading branch information
LdDl committed Apr 23, 2021
1 parent 360d101 commit d9257ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion v2/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Blobie interface {
PredictNextPosition(n int)
Update(newb Blobie) error
SetDraw(drawOptions *DrawOptions)
DrawTrack(mat *gocv.Mat, optionalText string)
DrawTrack(mat *gocv.Mat, optionalText ...string)
IsCrossedTheLine(vertical, leftX, rightX int, direction bool) bool
IsCrossedTheLineWithShift(vertical, leftX, rightX int, direction bool, shift int) bool
IsCrossedTheObliqueLine(leftX, leftY, rightX, rightY int, direction bool) bool
Expand Down
18 changes: 11 additions & 7 deletions v2/blob/kalman_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (b *KalmanBlobie) SetDraw(drawOptions *DrawOptions) {
}

// DrawTrack Draws blob's track [KalmanBlobie]
func (b *KalmanBlobie) DrawTrack(mat *gocv.Mat, optionalText string) {
func (b *KalmanBlobie) DrawTrack(mat *gocv.Mat, optionalText ...string) {
if b.drawingOptions == nil {
b.drawingOptions = NewDrawOptionsDefault()
}
Expand All @@ -228,12 +228,16 @@ func (b *KalmanBlobie) DrawTrack(mat *gocv.Mat, optionalText string) {
for i := range b.Track {
gocv.Circle(mat, b.Track[i], b.drawingOptions.CentroidColor.Radius, b.drawingOptions.CentroidColor.Color, b.drawingOptions.CentroidColor.Thickness)
}
if optionalText != "" {
pt := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y)
textSize := gocv.GetTextSize(optionalText, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Thickness)
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}}
gocv.Rectangle(mat, textRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
gocv.PutText(mat, optionalText, pt, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Color, b.drawingOptions.TextColor.Thickness)
shiftTextY := 10
for i := len(optionalText) - 1; i >= 0; i-- {
text := optionalText[i]
if text != "" {
anchor := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y-i*shiftTextY)
textSize := gocv.GetTextSize(text, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Thickness)
textRect := image.Rectangle{Min: image.Point{X: anchor.X, Y: anchor.Y - textSize.Y}, Max: image.Point{X: anchor.X + textSize.X, Y: anchor.Y}}
gocv.Rectangle(mat, textRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
gocv.PutText(mat, text, anchor, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Color, b.drawingOptions.TextColor.Thickness)
}
}
}
}
18 changes: 11 additions & 7 deletions v2/blob/simple_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (b *SimpleBlobie) SetDraw(drawOptions *DrawOptions) {
}

// DrawTrack Draws blob's track [SimpleBlobie]
func (b *SimpleBlobie) DrawTrack(mat *gocv.Mat, optionalText string) {
func (b *SimpleBlobie) DrawTrack(mat *gocv.Mat, optionalText ...string) {
if b.drawingOptions == nil {
b.drawingOptions = NewDrawOptionsDefault()
}
Expand All @@ -216,12 +216,16 @@ func (b *SimpleBlobie) DrawTrack(mat *gocv.Mat, optionalText string) {
for i := range b.Track {
gocv.Circle(mat, b.Track[i], b.drawingOptions.CentroidColor.Radius, b.drawingOptions.CentroidColor.Color, b.drawingOptions.CentroidColor.Thickness)
}
if optionalText != "" {
pt := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y)
textSize := gocv.GetTextSize(optionalText, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Thickness)
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}}
gocv.Rectangle(mat, textRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
gocv.PutText(mat, optionalText, pt, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Color, b.drawingOptions.TextColor.Thickness)
shiftTextY := 10
for i := len(optionalText) - 1; i >= 0; i-- {
text := optionalText[i]
if text != "" {
anchor := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y-i*shiftTextY)
textSize := gocv.GetTextSize(text, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Thickness)
textRect := image.Rectangle{Min: image.Point{X: anchor.X, Y: anchor.Y - textSize.Y}, Max: image.Point{X: anchor.X + textSize.X, Y: anchor.Y}}
gocv.Rectangle(mat, textRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
gocv.PutText(mat, text, anchor, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Color, b.drawingOptions.TextColor.Thickness)
}
}
}
}

0 comments on commit d9257ec

Please sign in to comment.