-
Notifications
You must be signed in to change notification settings - Fork 8
/
find.go
85 lines (67 loc) · 1.58 KB
/
find.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
package main
import (
"flag"
"log"
"runtime"
"time"
ab "local/adbbot"
)
var (
verbosity = flag.Int("v", 3, "verbosity")
ADB = flag.String("adb", "adb", "adb exec path")
DEV = flag.String("dev", "", "select device")
TMPL = flag.String("t", "tmpl.png", "template image")
IN = flag.String("i", "", "input image")
sizeX = flag.Int("sizeX", 720, "sizeX")
sizeY = flag.Int("sizeY", 1280, "sizeY")
)
func main() {
log.SetFlags(log.Ldate | log.Ltime)
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
ab.Verbosity = *verbosity
t := time.Now()
Vln(3, "[now]", t.Format("20060102_150405"), *ADB, *DEV)
// create matching template
tmpl, err := ab.NewTmpl(*TMPL, ab.RectAll)
if err != nil {
Vln(2, "load template image err", err)
return
}
if *IN != "" {
var x, y int
var val float64
input, err := ab.OpenImage(*IN)
if err != nil {
Vln(2, "load input image err", err)
}
x, y, val = ab.FindP(input, tmpl.Image)
if x == -1 && y == -1 {
Vln(2, "template not found", x, y, val)
} else {
Vln(2, "template found at", x, y, val)
}
return
}
bot := ab.NewLocalBot(*DEV, *ADB)
if *sizeX > 0 && *sizeY > 0 {
bot.ScriptScreen(0, 0, *sizeX, *sizeY)
}
// try to find target once
x, y, val := ab.FindExistReg(bot, tmpl, 2, 0)
if x == -1 && y == -1 {
Vln(2, "template not found", x, y, val)
} else {
Vln(2, "template found at", x, y, val)
}
}
func Vf(level int, format string, v ...interface{}) {
if level <= *verbosity {
log.Printf(format, v...)
}
}
func Vln(level int, v ...interface{}) {
if level <= *verbosity {
log.Println(v...)
}
}