-
Notifications
You must be signed in to change notification settings - Fork 17
/
ncc_test.go
49 lines (41 loc) · 1.17 KB
/
ncc_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
package lookup
import (
"image"
_ "image/png"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestNumerator(t *testing.T) {
Convey("Given two imageBinary structs", t, func() {
a1 := image.NewGray(image.Rect(0, 0, 2, 2))
a2 := image.NewGray(image.Rect(0, 0, 2, 2))
b1 := newImageBinaryChannel(a1, gray)
b2 := newImageBinaryChannel(a2, gray)
b1.zeroMeanImage = []float64{1, 2, 3, 4}
b2.zeroMeanImage = []float64{1, 2, 3, 4}
Convey("It sums all zeroMean images pixels", func() {
sum := numerator(b1, b2, 0, 0)
So(sum, ShouldEqual, 1+4+9+16)
})
})
}
var (
benchImg = loadImageColor("testdata/cyclopst1.png")
benchTemplate = loadImageColor("testdata/cyclopst3.png")
benchImgBin = newImageBinary(benchImg)
benchTemplateBin = newImageBinary(benchTemplate)
)
func BenchmarkLookupAll(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = lookupAll(benchImgBin, 0, 0, benchImgBin.width-1, benchImgBin.height-1, benchTemplateBin, 0.9)
}
}
func BenchmarkNumerator(b *testing.B) {
ci := benchImgBin.channels[0]
ct := benchTemplateBin.channels[0]
b.ReportAllocs()
for i := 0; i < b.N; i++ {
numerator(ci, ct, 0, 0)
}
}