forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoio_test.go
81 lines (66 loc) · 1.87 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
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 := VideoCaptureFile("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 TestVideoCaptureFile(t *testing.T) {
vc, _ := VideoCaptureFile("images/small.mp4")
defer vc.Close()
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")
}
}
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")
}
}