forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgcodecs_test.go
74 lines (62 loc) · 1.55 KB
/
imgcodecs_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
package gocv
import (
"io/ioutil"
"path/filepath"
"testing"
)
func TestIMRead(t *testing.T) {
img := IMRead("images/face-detect.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in IMRead")
}
}
func TestIMWrite(t *testing.T) {
dir, _ := ioutil.TempDir("", "gocvtests")
tmpfn := filepath.Join(dir, "test.jpg")
img := IMRead("images/face-detect.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid read of Mat in IMWrite test")
}
result := IMWrite(tmpfn, img)
if !result {
t.Error("Invalid write of Mat in IMWrite test")
}
}
func TestIMWriteWithParams(t *testing.T) {
dir, _ := ioutil.TempDir("", "gocvtests")
tmpfn := filepath.Join(dir, "test.jpg")
img := IMRead("images/face-detect.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid read of Mat in IMWrite test")
}
result := IMWriteWithParams(tmpfn, img, []int{IMWriteJpegQuality, 60})
if !result {
t.Error("Invalid write of Mat in IMWrite test")
}
}
func TestIMEncode(t *testing.T) {
img := IMRead("images/face-detect.jpg", IMReadColor)
if img.Empty() {
t.Error("Invalid Mat in IMEncode test")
}
buf, err := IMEncode(PNGFileExt, img)
if err != nil {
t.Error(err)
}
if len(buf) < 43000 {
t.Errorf("Wrong buffer size in IMEncode test. Should have been %v\n", len(buf))
}
}
func TestIMDecode(t *testing.T) {
content, err := ioutil.ReadFile("images/face-detect.jpg")
if err != nil {
t.Error("Invalid ReadFile in IMDecode")
}
dec, err := IMDecode(content, IMReadColor)
if err != nil {
t.Error(err.Error())
}
if dec.Empty() {
t.Error("Invalid Mat in IMDecode")
}
}