forked from deluan/lookup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_lookup_test.go
47 lines (37 loc) · 945 Bytes
/
examples_lookup_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
package lookup_test
import (
"fmt"
"image"
"os"
_ "image/png"
"github.com/deluan/lookup"
)
// Helper function to load an image from the filesystem
func loadImage(imgPath string) image.Image {
imageFile, _ := os.Open(imgPath)
defer imageFile.Close()
img, _, _ := image.Decode(imageFile)
return img
}
func Example_lookup() {
// Load full image
img := loadImage("testdata/cyclopst1.png")
// Create a lookup for that image
l := lookup.NewLookup(img)
// Load a template to search inside the image
template := loadImage("testdata/cyclopst3.png")
// Find all occurrences of the template in the image
pp, _ := l.FindAll(template, 0.9)
// Print the results
if len(pp) > 0 {
fmt.Printf("Found %d matches:\n", len(pp))
for _, p := range pp {
fmt.Printf("- (%d, %d) with %f accuracy\n", p.X, p.Y, p.G)
}
} else {
println("No matches found")
}
// Output:
// Found 1 matches:
// - (21, 7) with 0.997942 accuracy
}