-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathmain.go
46 lines (36 loc) · 945 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
46
package main
import (
"fmt"
"image"
_ "image/jpeg"
_ "image/png"
"log"
"os"
"github.com/muesli/smartcrop"
sclogger "github.com/muesli/smartcrop/logger"
"github.com/muesli/smartcrop/nfnt"
// "github.com/muesli/smartcrop/gocv"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Please give me an argument")
os.Exit(1)
}
f, _ := os.Open(os.Args[1])
img, _, _ := image.Decode(f)
l := sclogger.Logger{
DebugMode: true,
Log: log.New(os.Stderr, "", 0),
}
analyzer := smartcrop.NewAnalyzerWithLogger(nfnt.NewDefaultResizer(), l)
/*
To replace skin detection with gocv-based face detection:
analyzer.SetDetectors([]smartcrop.Detector{
&gocv.FaceDetector{"./cascade.xml", &l},
&smartcrop.SaturationDetector{},
})
*/
topCrop, _ := analyzer.FindBestCrop(img, 300, 200)
// The crop will have the requested aspect ratio, but you need to copy/scale it yourself
fmt.Printf("Top crop: %+v\n", topCrop)
}