Skip to content

Commit 9044c0c

Browse files
committed
add X-axis threshold
1 parent af735cf commit 9044c0c

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

blob/array_tracker.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,23 @@ func (b *Blobie) DrawTrack(mat *gocv.Mat, optionalText string) {
111111
}
112112

113113
// IsCrossedTheLine - Check if blob crossed the HORIZONTAL line
114-
func (b *Blobie) IsCrossedTheLine(horizontal int, direction bool) bool {
114+
func (b *Blobie) IsCrossedTheLine(vertical, leftX, rightX int, direction bool) bool {
115115
trackLen := len(b.Track)
116116
if b.isStillBeingTracked == true && trackLen >= 2 && b.crossedLine == false {
117117
prevFrame := trackLen - 2
118118
currFrame := trackLen - 1
119-
if direction {
120-
if b.Track[prevFrame].Y <= horizontal && b.Track[currFrame].Y > horizontal { // TO us
121-
b.crossedLine = true
122-
return true
123-
}
124-
} else {
125-
if b.Track[prevFrame].Y > horizontal && b.Track[currFrame].Y <= horizontal { // FROM us
126-
b.crossedLine = true
127-
return true
119+
if b.Track[currFrame].X >= leftX && b.Track[currFrame].X <= rightX {
120+
if direction {
121+
122+
if b.Track[prevFrame].Y <= vertical && b.Track[currFrame].Y > vertical { // TO us
123+
b.crossedLine = true
124+
return true
125+
}
126+
} else {
127+
if b.Track[prevFrame].Y > vertical && b.Track[currFrame].Y <= vertical { // FROM us
128+
b.crossedLine = true
129+
return true
130+
}
128131
}
129132
}
130133
}
@@ -133,20 +136,22 @@ func (b *Blobie) IsCrossedTheLine(horizontal int, direction bool) bool {
133136

134137
// IsCrossedTheLineWithShift - Check if blob crossed the HORIZONTAL line with shift along the Y-axis
135138
// Purpose of this for "predicative" cropping when detection line very close to bottom of image
136-
func (b *Blobie) IsCrossedTheLineWithShift(horizontal int, direction bool, shift int) bool {
139+
func (b *Blobie) IsCrossedTheLineWithShift(vertical, leftX, rightX int, direction bool, shift int) bool {
137140
trackLen := len(b.Track)
138141
if b.isStillBeingTracked == true && trackLen >= 2 && b.crossedLine == false {
139142
prevFrame := trackLen - 2
140143
currFrame := trackLen - 1
141-
if direction {
142-
if b.Track[prevFrame].Y <= horizontal && (b.Track[currFrame].Y+shift) > horizontal { // TO us
143-
b.crossedLine = true
144-
return true
145-
}
146-
} else {
147-
if b.Track[prevFrame].Y > horizontal && (b.Track[currFrame].Y+shift) <= horizontal { // FROM us
148-
b.crossedLine = true
149-
return true
144+
if b.Track[currFrame].X >= leftX && b.Track[currFrame].X <= rightX {
145+
if direction {
146+
if (b.Track[prevFrame].Y+shift) <= vertical && (b.Track[currFrame].Y+shift) > vertical { // TO us
147+
b.crossedLine = true
148+
return true
149+
}
150+
} else {
151+
if (b.Track[prevFrame].Y+shift) > vertical && (b.Track[currFrame].Y+shift) <= vertical { // FROM us
152+
b.crossedLine = true
153+
return true
154+
}
150155
}
151156
}
152157
}

blob/blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (b *Blobie) Update(newb Blobie) {
8585
b.Track = append(b.Track, newb.Center)
8686
// Restrict number of points in track (shift to the left)
8787
if len(b.Track) > b.maxPointsInTrack {
88-
b.Track = b.Track[1:]
88+
b.Track = b.Track[1:]
8989
}
9090
}
9191

0 commit comments

Comments
 (0)