Skip to content

Commit

Permalink
Merge e6128cc into f6ebaa7
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamCodeMan authored Sep 1, 2018
2 parents f6ebaa7 + e6128cc commit 26e301a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
32 changes: 32 additions & 0 deletions facedata.go

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions smartcrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import (

"github.com/muesli/smartcrop/options"

"github.com/esimov/pigo/core"
"github.com/llgcode/draw2d/draw2dimg"
"github.com/llgcode/draw2d/draw2dkit"
"golang.org/x/image/draw"
)

Expand Down Expand Up @@ -267,6 +270,11 @@ func analyse(logger Logger, img *image.RGBA, cropWidth, cropHeight, realMinScale
logger.Log.Println("Time elapsed sat:", time.Since(now))
debugOutput(logger.DebugMode, o, "saturation")

now = time.Now()
faceDetect(img, o)
logger.Log.Println("Time elapsed sat:", time.Since(now))
debugOutput(logger.DebugMode, o, "face")

now = time.Now()
var topCrop Crop
topScore := -1.0
Expand Down Expand Up @@ -430,6 +438,50 @@ func saturationDetect(i *image.RGBA, o *image.RGBA) {
}
}

func faceDetect(i *image.RGBA, o *image.RGBA) {
src := pigo.ImgToNRGBA(i)
pixels := pigo.RgbToGrayscale(src)
cols, rows := src.Bounds().Max.X, src.Bounds().Max.Y

cParams := pigo.CascadeParams{
MinSize: 20,
MaxSize: 1000,
ShiftFactor: 0.1,
ScaleFactor: 1.1,
}
imgParams := pigo.ImageParams{
Pixels: pixels,
Rows: rows,
Cols: cols,
Dim: cols,
}

cascadeFile, err := dataFace()
if err != nil {
log.Fatalf("Error reading the cascade file: %v", err)
}

pigo := pigo.NewPigo()

classifier, err := pigo.Unpack(cascadeFile)
if err != nil {
log.Fatalf("Error reading the cascade file: %s", err)
}

dets := classifier.RunCascade(imgParams, cParams)

faces := classifier.ClusterDetections(dets, 0.2)

gc := draw2dimg.NewGraphicContext(o)

for _, face := range faces {
draw2dkit.Ellipse(gc, float64(face.Col), float64(face.Row), float64(face.Scale/2), float64(face.Scale)/2)
gc.SetLineWidth(2.0)
gc.SetStrokeColor(color.RGBA{255, 0, 0, 255})
gc.Stroke()
}
}

func crops(i image.Image, cropWidth, cropHeight, realMinScale float64) []Crop {
res := []Crop{}
width := i.Bounds().Dx()
Expand Down

0 comments on commit 26e301a

Please sign in to comment.