Skip to content

Commit 2a12500

Browse files
committed
little tests for oblique and horizontal only line
1 parent c2a8d76 commit 2a12500

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

v2/blob/line_cross.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func (b *KalmanBlobie) IsCrossedTheObliqueLine(leftX, leftY, rightX, rightY int,
241241
// First segment is: P1 = (b.Track[prevFrame].X, b.Track[prevFrame].Y), Q1 = (b.Track[currFrame].X, b.Track[currFrame].Y)
242242
// Second segment is: P2 = (leftX, leftY), Q2 = (rightX, rightY)
243243
if isIntersects(b.Track[prevFrame].X, b.Track[prevFrame].Y, b.Track[currFrame].X, b.Track[currFrame].Y, leftX, leftY, rightX, rightY) {
244+
244245
if direction {
245246
if b.Track[currFrame].Y > b.Track[prevFrame].Y { // TO us
246247
b.crossedLine = true

v2/blob/line_cross_test.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,61 @@ func TestHorizontalLineTest(t *testing.T) {
2121

2222
for _, b := range allblobies.Objects {
2323
if b.IsCrossedTheLine(horizontalLine[0][1], horizontalLine[0][0], horizontalLine[1][0], direction) {
24-
t.Logf("Correct when direction is TO US")
24+
t.Logf("[HORIZONTAL] Correct when direction is TO US")
2525
} else {
26-
t.Logf("Incorrect when direction is TO US")
26+
t.Error("[HORIZONTAL] Incorrect when direction is TO US")
2727
}
2828

2929
if b.IsCrossedTheLine(horizontalLine[0][1], horizontalLine[0][0], horizontalLine[1][0], !direction) {
30-
t.Logf("Incorrect when direction is FROM US")
30+
t.Error("[HORIZONTAL] Incorrect when direction is FROM US")
3131
} else {
32-
t.Logf("Correct when direction is FROM US")
32+
t.Logf("[HORIZONTAL] Correct when direction is FROM US")
3333
}
3434
}
3535
}
3636

3737
func TestObliqueLineTest(t *testing.T) {
38+
shoudlCrossObliqueLine := [][]int{
39+
[]int{4, 35},
40+
[]int{71, 31},
41+
}
42+
shoudlNOTCrossObliqueLine := [][]int{
43+
[]int{4, 35},
44+
[]int{71, 45},
45+
}
46+
47+
direction := true // true - TO us
48+
allblobies := NewBlobiesDefaults()
49+
50+
simpleB_time0 := NewSimpleBlobie(image.Rect(26, 8, 44, 18), nil)
51+
simpleB_time1 := NewSimpleBlobie(image.Rect(26, 20, 44, 30), nil)
52+
simpleB_time2 := NewSimpleBlobie(image.Rect(26, 32, 44, 42), nil)
53+
54+
allblobies.MatchToExisting([]Blobie{simpleB_time0, simpleB_time1, simpleB_time2})
3855

56+
for _, b := range allblobies.Objects {
57+
if b.IsCrossedTheObliqueLine(shoudlCrossObliqueLine[0][0], shoudlCrossObliqueLine[0][1], shoudlCrossObliqueLine[1][0], shoudlCrossObliqueLine[1][1], direction) {
58+
t.Logf("[OBLIQUE] Correct when direction is TO US")
59+
} else {
60+
t.Error("[OBLIQUE ERR] Incorrect when direction is TO US")
61+
}
62+
63+
if b.IsCrossedTheObliqueLine(shoudlCrossObliqueLine[0][0], shoudlCrossObliqueLine[0][1], shoudlCrossObliqueLine[1][0], shoudlCrossObliqueLine[1][1], !direction) {
64+
t.Error("[OBLIQUE ERR] Incorrect when direction is FROM US")
65+
} else {
66+
t.Logf("[OBLIQUE] Correct when direction is FROM US")
67+
}
68+
69+
if b.IsCrossedTheObliqueLine(shoudlNOTCrossObliqueLine[0][0], shoudlNOTCrossObliqueLine[0][1], shoudlNOTCrossObliqueLine[1][0], shoudlNOTCrossObliqueLine[1][1], direction) {
70+
t.Error("[OBLIQUE NOT CROSS ERR] Incorrect when direction is TO US")
71+
} else {
72+
t.Logf("[OBLIQUE NOT CROSS] Correct when direction is TO US")
73+
}
74+
75+
if b.IsCrossedTheObliqueLine(shoudlNOTCrossObliqueLine[0][0], shoudlNOTCrossObliqueLine[0][1], shoudlNOTCrossObliqueLine[1][0], shoudlNOTCrossObliqueLine[1][1], !direction) {
76+
t.Error("[OBLIQUE NOT CROSS ERR] Incorrect when direction is FROM US")
77+
} else {
78+
t.Logf("[OBLIQUE NOT CROSS] Correct when direction is FROM US")
79+
}
80+
}
3981
}

v2/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.16
44

55
require (
66
github.com/LdDl/kalman-filter v0.1.1
7-
github.com/pkg/errors v0.9.1 // indirect
7+
github.com/pkg/errors v0.9.1
88
github.com/satori/go.uuid v1.2.0
99
gocv.io/x/gocv v0.23.0
10-
gonum.org/v1/gonum v0.9.1 // indirect
10+
gonum.org/v1/gonum v0.9.1
1111
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
1212
)

0 commit comments

Comments
 (0)