-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe_test.go
89 lines (64 loc) · 1.89 KB
/
pipe_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
package cvpipe
import (
"image"
"testing"
"gocv.io/x/gocv"
)
func TestCloseNewPipe(t *testing.T) {
pipe := NewPipe("test", PipeOptions{})
defer pipe.Close()
}
func TestNewPipeMat(t *testing.T) {
mat := gocv.NewMat()
defer mat.Close()
pipeMat := NewPipeMat(mat)
defer pipeMat.Close()
}
func TestRunEmptyPipe(t *testing.T) {
pipe := NewPipe("test", PipeOptions{})
defer pipe.Close()
img := gocv.NewMat()
defer img.Close()
mat := NewPipeMat(img)
defer mat.Close()
result := pipe.Run(mat)
defer result.Close()
if !result.mat.Empty() {
t.Error("non-empty result")
}
}
func TestRunEmptyPipeWithBlankImage(t *testing.T) {
pipe := NewPipe("test", PipeOptions{})
defer pipe.Close()
imageSize := 10
img := gocv.NewMatWithSizeFromScalar(gocv.NewScalar(0, 0, 0, 0), imageSize, imageSize, gocv.MatTypeCV8U)
defer img.Close()
mat := NewPipeMat(img)
defer mat.Close()
result := pipe.Run(mat)
defer result.Close()
if result.mat.Empty() {
t.Error("empty result")
}
if result.mat.Rows() != imageSize || result.mat.Cols() != imageSize {
t.Errorf("unexpected result size: got %dx%d, want %dx%d", result.mat.Rows(), result.mat.Cols(), imageSize, imageSize)
}
}
func TestRunPipeInvertImage(t *testing.T) {
pipe := NewPipe("test", PipeOptions{})
defer pipe.Close()
imageSize := 10
img := gocv.NewMatWithSizeFromScalar(gocv.NewScalar(255, 255, 255, 255), imageSize, imageSize, gocv.MatTypeCV8U)
mat := NewPipeMat(img)
defer mat.Close()
resizeFactor := 0.5
result := pipe.Add(NewResize(image.Point{}, resizeFactor, resizeFactor, gocv.InterpolationDefault)).Run(mat)
defer result.Close()
if result.mat.Empty() {
t.Error("empty result")
}
wantSize := int(float64(imageSize) * resizeFactor)
if result.mat.Rows() != wantSize || result.mat.Cols() != wantSize {
t.Errorf("unexpected result size: got %dx%d, want %dx%d", result.mat.Rows(), result.mat.Cols(), wantSize, wantSize)
}
}