-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
54 lines (45 loc) · 1.05 KB
/
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
46
47
48
49
50
51
52
53
54
package main
import (
"image/jpeg"
_ "image/png"
"log"
"os"
"github.com/rocketlaunchr/showerglass/core"
)
func main() {
f, err := os.Open("face.jpg")
if err != nil {
log.Fatalf("Error opening the file: %v", err)
}
defer f.Close()
opts := showerglass.Options{
NewHeight: 100.0,
NewWidth: 100.0,
ResizeAlg: showerglass.CatmullRom,
TriangleConfig: func(QRank, facearea int, Q float32, h, w int, c showerglass.MaxPoints) *showerglass.TriangleConfig {
if QRank < 1 {
// only modify first detected face
return &showerglass.TriangleConfig{
MaxPoints: 4000,
BlurRadius: 4,
BlurFactor: 1,
EdgeFactor: 6,
PointRate: 0.075,
}
}
return nil
},
}
filtered, _, err := showerglass.FaceMask(f, opts)
if err != nil {
log.Fatalf("Error aplying filter: %v", err)
}
out, err := os.Create("facemask.jpg")
if err != nil {
log.Fatalf("Error writing the file: %s", err)
}
err = jpeg.Encode(out, filtered, &jpeg.Options{Quality: 100})
if err != nil {
log.Fatalf("Error encoding to file: %s", err)
}
}