-
Notifications
You must be signed in to change notification settings - Fork 24
/
scoring.go
61 lines (51 loc) · 1.2 KB
/
scoring.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
package main
import (
"errors"
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"os"
"gocv.io/x/gocv"
)
// get score from yahoo open nsfw https://github.com/yahoo/open_nsfw
func getOpenNsfwScore(filePath string, net gocv.Net) (score float32, err error) {
img := gocv.IMRead(filePath, gocv.IMReadColor)
if img.Empty() {
return 0, errors.New("Invalid image")
}
defer img.Close()
blob := gocv.BlobFromImage(
img,
1.0,
image.Pt(224, 224),
gocv.NewScalar(104, 117, 123, 0),
true,
false,
)
if blob.Empty() {
return 0, errors.New("Invalid blob")
}
defer blob.Close()
net.SetInput(blob, "")
detBlob := net.Forward("")
defer detBlob.Close()
return detBlob.GetFloatAt(0, 1), nil
}
// get result from An Algorithm for Nudity Detection by Rigan Ap-apid
func getAnAlgorithmForNudityDetectionResult(filePath string, debug bool) (result bool, err error) {
existingImageFile, err := os.Open(filePath)
if err != nil {
return true, errors.New("Cant open file")
}
defer existingImageFile.Close()
imageData, _, err := image.Decode(existingImageFile)
if err != nil {
return true, errors.New("Decode err")
}
anAlg := anAlgorithm{
img: imageData,
debug: debug,
}
return anAlg.IsNude()
}