-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoption.go
More file actions
46 lines (39 loc) · 970 Bytes
/
option.go
File metadata and controls
46 lines (39 loc) · 970 Bytes
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
package facenet
import (
"github.com/bububa/facenet/core"
"github.com/bububa/facenet/imageutil"
)
// Option face instance option interface
type Option interface {
apply(*Estimator) error
}
type optionFunc func(ins *Estimator) error
func (fn optionFunc) apply(ins *Estimator) error {
return fn(ins)
}
// WithModel set net model with model path
func WithModel(modelPath string) Option {
return optionFunc(func(ins *Estimator) error {
ins.model = core.NewNet(modelPath)
return nil
})
}
// WithDB set db with dbpath
func WithDB(dbPath string) Option {
return optionFunc(func(ins *Estimator) error {
if ins.db == nil {
ins.db = NewStorage(nil, nil)
}
return ins.db.Load(dbPath)
})
}
// WithFontPath set font with font path
func WithFontPath(fontPath string) Option {
return optionFunc(func(ins *Estimator) error {
if ins.font == nil {
ins.font = new(imageutil.Font)
}
ins.font.Cache = imageutil.NewFontCache(fontPath)
return nil
})
}