-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
45 lines (40 loc) · 891 Bytes
/
main.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
package main
import (
"github.com/jessevdk/go-flags"
"github.com/lon9/waifu2x-go/waifu2x"
"os"
"runtime"
)
func main() {
opts := &Options{}
parser := flags.NewParser(opts, flags.Default)
parser.Name = "waifu2x-go"
parser.Usage = "-i[--input] <input-image-path> -o[--output] <output-image-path> -m[--model] <model-path> -c[--cpu] <the-number-of-cpus>"
_, err := parser.Parse()
if err != nil {
os.Exit(1)
}
iptImageName := opts.Input
optImageName := opts.Output
if optImageName == "" {
optImageName = "dst.png"
}
modelName := opts.ModelName
numCPU := opts.CPU
cpus := runtime.NumCPU()
if numCPU != 0 {
if numCPU > cpus {
runtime.GOMAXPROCS(cpus)
} else {
runtime.GOMAXPROCS(numCPU)
}
}
w, err := waifu2x.NewWaifu2x(modelName, iptImageName)
if err != nil {
panic(err)
}
w.Exec()
if err = w.SaveImage(optImageName); err != nil {
panic(err)
}
}