-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetector_test.go
70 lines (56 loc) · 1.67 KB
/
detector_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
package faceapi_test
import (
"testing"
"github.com/tasdomas/faceapi"
. "launchpad.net/gocheck"
)
func Test(t *testing.T) {
TestingT(t)
}
type TSuite struct{}
const (
HAAR_CASCADE_FILE = "data/haarcascade_frontalface_alt.xml"
IMAGE_FILE = "data/lena.jpg"
)
var _ = Suite(&TSuite{})
// Test initializing detector with non-existant file fails.
func (t *TSuite) TestNonExistantFile(c *C) {
detector, err := faceapi.NewDetector("nonexistantfile.xml")
c.Assert(detector, IsNil)
c.Assert(err, ErrorMatches, "Classifier file does not exist.")
}
// Test detector initialization.
func (t *TSuite) TestDetectorInit(c *C) {
detector, err := faceapi.NewDetector(HAAR_CASCADE_FILE)
c.Assert(detector, NotNil)
c.Assert(err, IsNil)
}
// Test detector fails when image file does not exist.
func (t *TSuite) TestNoImage(c *C) {
detector, err := faceapi.NewDetector(HAAR_CASCADE_FILE)
c.Assert(detector, NotNil)
c.Assert(err, IsNil)
result, err := detector.FindInFile("nonexistantimage.jpg")
c.Assert(result.Objects, HasLen, 0)
c.Assert(err, ErrorMatches, "Failed to load image from file.")
}
// Test detection on image file.
func (t *TSuite) TestImageFile(c *C) {
detector, err := faceapi.NewDetector(HAAR_CASCADE_FILE)
c.Assert(detector, NotNil)
c.Assert(err, IsNil)
result, err := detector.FindInFile(IMAGE_FILE)
c.Assert(result.Objects, HasLen, 1)
c.Assert(err, IsNil)
}
// Benchmark detection on image file..
func (t *TSuite) BenchmarkDetection(c *C) {
detector, err := faceapi.NewDetector(HAAR_CASCADE_FILE)
c.Assert(detector, NotNil)
c.Assert(err, IsNil)
c.ResetTimer()
for i := 0; i < c.N; i++ {
_, err := detector.FindInFile(IMAGE_FILE)
c.Assert(err, IsNil)
}
}