Skip to content

Commit b42b9ad

Browse files
committed
text shift calculation is refactored
1 parent cda97f1 commit b42b9ad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

v2/blob/kalman_blob.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ func (b *KalmanBlobie) DrawTrack(mat *gocv.Mat, optionalText ...string) {
229229
gocv.Circle(mat, b.Track[i], b.drawingOptions.CentroidColor.Radius, b.drawingOptions.CentroidColor.Color, b.drawingOptions.CentroidColor.Thickness)
230230
}
231231
shiftTextY := 0
232-
for i := len(optionalText) - 1; i >= 0; i-- {
232+
for i := 0; i < len(optionalText); i++ {
233233
text := optionalText[i]
234234
if text != "" {
235-
anchor := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y-i*shiftTextY)
236235
textSize := gocv.GetTextSize(text, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Thickness)
236+
anchor := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y-shiftTextY-b.drawingOptions.BBoxColor.Thickness) // substract extra margin = Thickness of BBox
237237
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}}
238238
gocv.Rectangle(mat, textRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
239239
gocv.PutText(mat, text, anchor, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Color, b.drawingOptions.TextColor.Thickness)
240-
shiftTextY = textSize.Y
240+
shiftTextY += textSize.Y
241241
}
242242
}
243243
}

v2/blob/simple_blob.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ func (b *SimpleBlobie) DrawTrack(mat *gocv.Mat, optionalText ...string) {
217217
gocv.Circle(mat, b.Track[i], b.drawingOptions.CentroidColor.Radius, b.drawingOptions.CentroidColor.Color, b.drawingOptions.CentroidColor.Thickness)
218218
}
219219
shiftTextY := 0
220-
for i := len(optionalText) - 1; i >= 0; i-- {
220+
for i := 0; i < len(optionalText); i++ {
221221
text := optionalText[i]
222222
if text != "" {
223-
anchor := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y-i*shiftTextY)
224223
textSize := gocv.GetTextSize(text, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Thickness)
224+
anchor := image.Pt(b.CurrentRect.Min.X, b.CurrentRect.Min.Y-shiftTextY-b.drawingOptions.BBoxColor.Thickness) // substract extra margin = Thickness of BBox
225225
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}}
226226
gocv.Rectangle(mat, textRect, b.drawingOptions.BBoxColor.Color, b.drawingOptions.BBoxColor.Thickness)
227227
gocv.PutText(mat, text, anchor, b.drawingOptions.TextColor.Font, b.drawingOptions.TextColor.Scale, b.drawingOptions.TextColor.Color, b.drawingOptions.TextColor.Thickness)
228-
shiftTextY = textSize.Y
228+
shiftTextY += textSize.Y
229229
}
230230
}
231231
}

0 commit comments

Comments
 (0)