forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_test.go
122 lines (92 loc) · 2.37 KB
/
video_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package gocv
import (
"image"
"testing"
)
func TestMOG2(t *testing.T) {
img := IMRead("images/face.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in MOG2 test")
}
defer img.Close()
dst := NewMat()
defer dst.Close()
mog2 := NewBackgroundSubtractorMOG2()
defer mog2.Close()
mog2.Apply(img, &dst)
if dst.Empty() {
t.Error("Error in TestMOG2 test")
}
}
func TestKNN(t *testing.T) {
img := IMRead("images/face.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in KNN test")
}
defer img.Close()
dst := NewMat()
defer dst.Close()
knn := NewBackgroundSubtractorKNN()
defer knn.Close()
knn.Apply(img, &dst)
if dst.Empty() {
t.Error("Error in TestKNN test")
}
}
func TestCalcOpticalFlowFarneback(t *testing.T) {
img1 := IMRead("images/face.jpg", IMReadColor)
if img1.Empty() {
t.Error("Invalid Mat in CalcOpticalFlowFarneback test")
}
defer img1.Close()
dest := NewMat()
defer dest.Close()
CvtColor(img1, &dest, ColorBGRAToGray)
img2 := dest.Clone()
flow := NewMat()
defer flow.Close()
CalcOpticalFlowFarneback(dest, img2, &flow, 0.4, 1, 12, 2, 8, 1.2, 0)
if flow.Empty() {
t.Error("Error in CalcOpticalFlowFarneback test")
}
if flow.Rows() != 480 {
t.Errorf("Invalid CalcOpticalFlowFarneback test rows: %v", flow.Rows())
}
if flow.Cols() != 640 {
t.Errorf("Invalid CalcOpticalFlowFarneback test cols: %v", flow.Cols())
}
}
func TestCalcOpticalFlowPyrLK(t *testing.T) {
img1 := IMRead("images/face.jpg", IMReadColor)
if img1.Empty() {
t.Error("Invalid Mat in CalcOpticalFlowPyrLK test")
}
defer img1.Close()
dest := NewMat()
defer dest.Close()
CvtColor(img1, &dest, ColorBGRAToGray)
img2 := dest.Clone()
prevPts := NewMat()
defer prevPts.Close()
nextPts := NewMat()
defer nextPts.Close()
status := NewMat()
defer status.Close()
err := NewMat()
defer err.Close()
corners := NewMat()
defer corners.Close()
GoodFeaturesToTrack(dest, &corners, 500, 0.01, 10)
tc := NewTermCriteria(Count|EPS, 20, 0.03)
CornerSubPix(dest, &corners, image.Pt(10, 10), image.Pt(-1, -1), tc)
CalcOpticalFlowPyrLK(dest, img2, corners, nextPts, &status, &err)
if status.Empty() {
t.Error("Error in CalcOpticalFlowPyrLK test")
}
if status.Rows() != 323 {
t.Errorf("Invalid CalcOpticalFlowPyrLK test rows: %v", status.Rows())
}
if status.Cols() != 1 {
t.Errorf("Invalid CalcOpticalFlowPyrLK test cols: %v", status.Cols())
}
}