-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathspeed_estimation_test.go
More file actions
67 lines (62 loc) · 1.82 KB
/
Copy pathspeed_estimation_test.go
File metadata and controls
67 lines (62 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package odam
import (
"testing"
"time"
"gocv.io/x/gocv"
)
func TestGetPerspectiveTransformer(t *testing.T) {
src := []gocv.Point2f{
{X: float32(1200), Y: float32(278)},
{X: float32(87), Y: float32(328)},
{X: float32(36), Y: float32(583)},
{X: float32(1205), Y: float32(698)},
}
dst := []gocv.Point2f{
{X: float32(6.602018), Y: float32(52.036769)},
{X: float32(6.603227), Y: float32(52.036181)},
{X: float32(6.603638), Y: float32(52.036558)},
{X: float32(6.603560), Y: float32(52.036730)},
}
transformMat, converter := GetPerspectiveTransformer(src, dst)
for i, p := range src {
res := converter(p)
if res != dst[i] {
t.Errorf("Incorrect perspective transformation. Should be be %v, but got %v", dst[i], res)
}
}
transformMat.Close()
}
func TestHaversine(t *testing.T) {
src := gocv.Point2f{X: 6.602018, Y: 52.036769}
dst := gocv.Point2f{X: 6.603560, Y: 52.036730}
dist := Haversine(src, dst)
correctGreatCircleDistance := float32(0.105567716)
if dist != correctGreatCircleDistance {
t.Errorf("Great circle distance should be %f, but got %f", correctGreatCircleDistance, dist)
}
}
func TestEstimateSpeed(t *testing.T) {
srcMat := []gocv.Point2f{
{X: 1200, Y: 278},
{X: 87, Y: 328},
{X: 36, Y: 583},
{X: 1205, Y: 698},
}
dstMat := []gocv.Point2f{
{X: 6.602018, Y: 52.036769},
{X: 6.603227, Y: 52.036181},
{X: 6.603638, Y: 52.036558},
{X: 6.603560, Y: 52.036730},
}
transformMat, converter := GetPerspectiveTransformer(srcMat, dstMat)
src := gocv.Point2f{X: 1200, Y: 278}
dst := gocv.Point2f{X: 1205, Y: 698}
start := time.Now()
finish := start.Add(6000 * time.Millisecond)
res := EstimateSpeed(src, dst, start, finish, converter)
correctSpeed := float32(63.30266)
transformMat.Close()
if res != correctSpeed {
t.Errorf("Estimated speed should be %f, but got %f", res, correctSpeed)
}
}