Skip to content

Commit

Permalink
Merge pull request #13 from VoycerAG/smartcrop
Browse files Browse the repository at this point in the history
Add optional face recognition
  • Loading branch information
sharpner committed Jan 12, 2016
2 parents a91014c + 09bf608 commit c18571d
Show file tree
Hide file tree
Showing 21 changed files with 26,786 additions and 93 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
server/resizer/testimages/*
server/resizer/testimages_output/*
!server/resizer/testimages/.gitkeep
!server/resizer/testimages_output/.gitkeep
Godeps/_workspace
Godeps/Readme
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ go:
- tip

before_install:
- sudo apt-get update
- sudo add-apt-repository -y ppa:kubuntu-ppa/backports
- sudo apt-get update -qq
- sudo apt-get install -qq imagemagick
- sudo apt-get install libcv-dev libopencv-dev libopencv-contrib-dev libhighgui-dev libopencv-photo-dev libopencv-imgproc-dev libopencv-stitching-dev libopencv-superres-dev libopencv-ts-dev libopencv-videostab-dev

services: mongodb

Expand Down
37 changes: 23 additions & 14 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,40 @@ Compilation:

Install project using ```go get github.com/VoycerAG/gridfs-image-server```


Face Recognition:
----
The image server can provide experimental face detection for all images. In order to use this feature you need to install
openCV in order for the compilation to succeed. This will disable cross compilation compatibilities, since it makes heave use of cgo.

The current algorithm is pretty unconfident and only selects faces if it is about 90% sure that it will actually improve results. This is to be improved in future releases.
## Dependencies on Linux:
```
libcv-dev libopencv-dev libopencv-contrib-dev libhighgui-dev libopencv-photo-dev libopencv-imgproc-dev libopencv-stitching-dev libopencv-superres-dev libopencv-ts-dev libopencv-videostab-dev
```

## Dependencies on Mac OS X:
```
brew tap homebrew/science
brew install opencv
```

After you have installed all dependencies you can use ```go get -tags=facedetection github.com/VoycerAG/gridfs-image-server``` to install the server with face detection support.

Instructions
-----
```
-config string
path to the configuration file (default "configuration.json")
path to the configuration file (default "configuration.json")
-host string
the database host with an optional port, localhost would suffice (default "localhost:27017")
the database host with an optional port, localhost would suffice (default "localhost:27017")
-license string
your newrelic license key in order to enable monitoring
your newrelic license key in order to enable monitoring
-port int
the server port where we will serve images (default 8000)
the server port where we will serve images (default 8000)
(only with buildtag +facedetection)
-haarcascade string
haarcascade file path
```

Image Server Configuration
Expand Down
31 changes: 31 additions & 0 deletions advanced-application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// +build facedetection

package main

import (
"flag"
"log"

"github.com/VoycerAG/gridfs-image-server/server/paint"
"github.com/VoycerAG/gridfs-image-server/server/resizer"
)

// main starts the server and returns an invalid result as exit code
func main() {
haarcascade := flag.String("haarcascade", "", "haarcascade file path")
flag.Parse()

if *configurationFilepath == "" {
log.Fatal("configuration must be given")
return
}
if *haarcascade == "" {
log.Fatal("haarcascade file must be set")
return
}

smartcrop := resizer.NewSmartcrop(*haarcascade, paint.CropResizer{})
paint.AddResizer(resizer.TypeSmartcrop, smartcrop)

run(*host, *configurationFilepath, *newrelicKey, *serverPort)
}
88 changes: 88 additions & 0 deletions advanced-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"allowedEntries" : [
{
"name" : "smart2",
"width" : 200,
"height" : 150,
"type" : "smartcrop"
},
{
"name" : "smart0",
"width" : 45,
"height" : 35,
"type" : "smartcrop"
},
{
"name" : "45x35",
"width" : 45,
"height" : 35,
"type" : "fit"
},
{
"name" : "smart1",
"width" : 294,
"height" : 300,
"type" : "smartcrop"
},
{
"name" : "294x300",
"width" : 294,
"height" : 300,
"type" : "fit"
},
{
"name" : "294x210",
"width" : 294,
"height" : 210,
"type" : "crop"
},
{
"name" : "105x95",
"width" : 105,
"height" : 95,
"type" : "crop"
},
{
"name" : "288x200",
"width" : 288,
"height" : 200,
"type" : "crop"
},
{
"name" : "50x40",
"width" : 50,
"height" : 40,
"type" : "crop"
},
{
"name" : "50x50",
"width" : 50,
"height" : 50,
"type" : "crop"
},
{
"name" : "130x260",
"width" : 130,
"height" : 260,
"type" : "fit"
},
{
"name" : "310x230",
"width" : 310,
"height" : 230,
"type" : "fit"
},
{
"name" : "302x302",
"width" : 302,
"height" : 302,
"type" : "fit"
},
{
"name" : "150x150",
"width" : 150,
"height" : 150,
"type" : "crop"
}
]
}
45 changes: 3 additions & 42 deletions application.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,20 @@
// +build !facedetection

package main

import (
"flag"
"fmt"
"log"
"net/http"

"gopkg.in/mgo.v2"

"github.com/VoycerAG/gridfs-image-server/server"
)

// main starts the server and returns an invalid result as exit code
func main() {
configurationFilepath := flag.String("config", "configuration.json", "path to the configuration file")
serverPort := flag.Int("port", 8000, "the server port where we will serve images")
host := flag.String("host", "localhost:27017", "the database host with an optional port, localhost would suffice")
newrelicKey := flag.String("license", "", "your newrelic license key in order to enable monitoring")

flag.Parse()

if *configurationFilepath == "" {
log.Fatal("configuration must be given")
return
}

config, err := server.NewConfigFromFile(*configurationFilepath)
if err != nil {
log.Fatal(err)
return
}

session, err := mgo.Dial(*host)
if err != nil {
log.Fatal(err)
return
}

session.SetSyncTimeout(0)
session.SetMode(mgo.Eventual, true)

storage, err := server.NewGridfsStorage(session)
if err != nil {
log.Fatal(err)
return
}

imageServer := server.NewImageServerWithNewRelic(config, storage, *newrelicKey)

handler := imageServer.Handler()

log.Printf("Server started. Listening on %d database host is %s\n", *serverPort, *host)

err = http.ListenAndServe(fmt.Sprintf(":%d", *serverPort), handler)
if err != nil {
log.Fatal(err)
}
run(*host, *configurationFilepath, *newrelicKey, *serverPort)
}
59 changes: 59 additions & 0 deletions basic-application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"flag"
"fmt"
"log"
"net/http"

"github.com/VoycerAG/gridfs-image-server/server"
"gopkg.in/mgo.v2"
)

var (
configurationFilepath *string
serverPort *int
host *string
newrelicKey *string
)

func init() {
configurationFilepath = flag.String("config", "configuration.json", "path to the configuration file")
serverPort = flag.Int("port", 8000, "the server port where we will serve images")
host = flag.String("host", "localhost:27017", "the database host with an optional port, localhost would suffice")
newrelicKey = flag.String("license", "", "your newrelic license key in order to enable monitoring")
}

func run(mongoHost, configFile, newrelicToken string, port int) {
session, err := mgo.Dial(*host)
if err != nil {
log.Fatal(err)
return
}

config, err := server.NewConfigFromFile(configFile)
if err != nil {
log.Fatal(err)
return
}

session.SetSyncTimeout(0)
session.SetMode(mgo.Eventual, true)

storage, err := server.NewGridfsStorage(session)
if err != nil {
log.Fatal(err)
return
}

imageServer := server.NewImageServerWithNewRelic(config, storage, newrelicToken)

handler := imageServer.Handler()

log.Printf("Server started. Listening on %d database host is %s\n", port, mongoHost)

err = http.ListenAndServe(fmt.Sprintf(":%d", port), handler)
if err != nil {
log.Fatal(err)
}
}
Loading

0 comments on commit c18571d

Please sign in to comment.