-
Notifications
You must be signed in to change notification settings - Fork 5
/
cascade_classifier_test.go
106 lines (103 loc) · 2.68 KB
/
cascade_classifier_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
package opencv
import (
. "github.com/smartystreets/goconvey/convey"
"gopkg.in/sensorbee/sensorbee.v0/core"
"gopkg.in/sensorbee/sensorbee.v0/data"
"io/ioutil"
"os"
"testing"
)
func TestNewCascadeClassifier(t *testing.T) {
Convey("Given a SensorBee's core.Context", t, func() {
ctx := &core.Context{}
Convey("When create state with empty map", func() {
params := data.Map{}
_, err := NewCascadeClassifier(ctx, params)
Convey("Then should return an error", func() {
So(err, ShouldNotBeNil)
})
})
Convey("When create state with not exist file name", func() {
params := data.Map{
"file": data.String("not_exist_file"),
}
_, err := NewCascadeClassifier(ctx, params)
Convey("Then should return an error", func() {
So(err, ShouldNotBeNil)
})
})
Convey("When create state with file name", func() {
xml := `<?xml version="1.0"?>
<opencv_storage>
<cascade>
<stageType>BOOST</stageType>
<featureType>LBP</featureType>
<height>34</height>
<width>20</width>
<stageParams>
<boostType>GAB</boostType>
<minHitRate>0.1</minHitRate>
<maxFalseAlarm>0.1</maxFalseAlarm>
<weightTrimRate>0.1</weightTrimRate>
<maxDepth>1</maxDepth>
<maxWeakCount>100</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>256</maxCatCount>
<featSize>1</featSize></featureParams>
<stageNum>0</stageNum>
<stages></stages>
<features>
<_>
<rect></rect></_>
</features>
</cascade>
</opencv_storage>
`
err := ioutil.WriteFile("_test_for_face_detect.xml", []byte(xml), 0644)
So(err, ShouldBeNil)
Reset(func() {
os.Remove("_test_for_face_detect.xml")
})
params := data.Map{
"file": data.String("_test_for_face_detect.xml"),
}
st, err := NewCascadeClassifier(ctx, params)
So(err, ShouldBeNil)
Reset(func() {
st.Terminate(ctx)
})
Convey("Then state should be created", func() {
cc, ok := st.(*cascadeClassifier)
So(ok, ShouldBeTrue)
So(cc.classifier, ShouldNotBeNil)
})
})
})
}
func TestNewSharedImage(t *testing.T) {
Convey("Given a SensorBee's core.Context", t, func() {
ctx := &core.Context{}
Convey("When create state with empty map", func() {
params := data.Map{}
_, err := NewSharedImage(ctx, params)
Convey("Then should return an error", func() {
So(err, ShouldNotBeNil)
})
})
Convey("When create state with file name", func() {
params := data.Map{
"file": data.String("not_exist.png"),
}
st, err := NewSharedImage(ctx, params)
So(err, ShouldBeNil)
Reset(func() {
st.Terminate(ctx)
})
Convey("Then state should be created", func() {
cc, ok := st.(*sharedImage)
So(ok, ShouldBeTrue)
So(cc.img, ShouldNotBeNil)
})
})
})
}