forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoio_test.go
123 lines (102 loc) · 3 KB
/
videoio_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
123
package gocv
import (
"io/ioutil"
"path/filepath"
"strings"
"testing"
)
func TestVideoCaptureEmptyNumericalParameters(t *testing.T) {
_, err := VideoWriterFile(
"images/small.mp4", "MJPEG", 0, 0, 0, true)
if err == nil {
t.Error("Must fail due to an empty numerical parameters.")
}
if !strings.Contains(err.Error(), "one of the numerical parameters is equal to zero") {
t.Errorf("Must fail due to an empty numerical "+
"parameters, but have different error: %v", err)
}
}
func TestVideoCaptureCodecString(t *testing.T) {
vc, err := OpenVideoCapture("images/small.mp4")
if err != nil {
t.Errorf("TestVideoCaptureCodecString: error loading a file: %v", err)
}
if vc.CodecString() == "" {
t.Fatal("TestVideoCaptureCodecString: empty codec string")
}
}
func TestVideoCaptureCodecConversion(t *testing.T) {
vc, err := OpenVideoCapture("images/small.mp4")
if err != nil {
t.Errorf("TestVideoCaptureCodecConversion: error loading a file: %v", err)
}
if vc.CodecString() == "" {
t.Fatal("TestVideoCaptureCodecConversion: empty codec string")
}
if int64(vc.ToCodec(vc.CodecString())) != int64(vc.Get(VideoCaptureFOURCC)) {
t.Fatal("TestVideoCaptureCodecConversion: codec conversion failed")
}
}
func TestVideoCaptureCodecConversionBadInput(t *testing.T) {
vc, err := OpenVideoCapture("images/small.mp4")
if err != nil {
t.Errorf("TestVideoCaptureCodecConversionBadInput: error loading a file: %v", err)
}
codec := vc.ToCodec("BAD CODEC")
if int64(codec) != -1 {
t.Fatal("TestVideoCaptureCodecConversionBadInput: input validation failed")
}
}
func TestVideoCaptureInvalid(t *testing.T) {
_, err := OpenVideoCapture(1.1)
if err == nil {
t.Errorf("Should return error with invalid param")
}
}
func TestVideoCaptureFile(t *testing.T) {
vc, err := VideoCaptureFile("images/small.mp4")
defer vc.Close()
if err != nil {
t.Errorf("%s", err)
}
if !vc.IsOpened() {
t.Error("Unable to open VideoCaptureFile")
}
if fw := vc.Get(VideoCaptureFrameWidth); int(fw) != 560 {
t.Errorf("Expected frame width property of 560.0 got %f", fw)
}
if fh := vc.Get(VideoCaptureFrameHeight); int(fh) != 320 {
t.Errorf("Expected frame height property of 320.0 got %f", fh)
}
vc.Set(VideoCaptureBrightness, 100.0)
vc.Grab(10)
img := NewMat()
defer img.Close()
vc.Read(&img)
if img.Empty() {
t.Error("Unable to read VideoCaptureFile")
}
vc2, err := VideoCaptureFile("nonexistent.mp4")
defer vc2.Close()
if err == nil {
t.Errorf("Expected error when opening invalid file")
}
}
func TestVideoWriterFile(t *testing.T) {
dir, _ := ioutil.TempDir("", "gocvtests")
tmpfn := filepath.Join(dir, "test.avi")
img := IMRead("images/face-detect.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid read of Mat in VideoWriterFile test")
}
defer img.Close()
vw, _ := VideoWriterFile(tmpfn, "MJPG", 25, img.Cols(), img.Rows(), true)
defer vw.Close()
if !vw.IsOpened() {
t.Error("Unable to open VideoWriterFile")
}
err := vw.Write(img)
if err != nil {
t.Error("Invalid Write() in VideoWriter")
}
}