GithubHelp home page GithubHelp logo

linecode / pigo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from esimov/pigo

0.0 1.0 0.0 380 KB

Golang implementation of Pico face detection library.

Home Page: https://github.com/nenadmarkus/pico

License: MIT License

Makefile 0.74% Shell 6.86% Go 89.18% Python 3.22%

pigo's Introduction

pigo

Build Status GoDoc license release

Pigo is a face detection library implemented in Go based on Pixel Intensity Comparison-based Object detection paper (https://arxiv.org/pdf/1305.4537.pdf).

Rectangle face marker Circle face marker
rectangle circle

Motivation

I've intended to implement this face detection method in Go, since the only existing solution for face detection in the Go ecosystem is using bindings to OpenCV, but installing OpenCV on various platforms is sometimes daunting.

This library does not require any third party modules to be installed. However in case you wish to try the real time, webcam based face detection you might need to have Python2 and OpenCV installed, but the core API does not require any third party and external modules.

Since I haven't found any viable existing solution for accessing webcam in Go, Python is used for capturing the webcam and transferring the binary data to Go through exec.CommandContext method.

Key features

  • High processing speed.
  • There is no need for image preprocessing prior to detection.
  • There is no need for the computation of integral images, image pyramid, HOG pyramid or any other similar data structure.
  • The face detection is based on pixel intensity comparison encoded in the binary file dat tree structure.

Todo

  • Object rotation detection.

Install

Install Go, set your GOPATH, and make sure $GOPATH/bin is on your PATH.

$ export GOPATH="$HOME/go"
$ export PATH="$PATH:$GOPATH/bin"

Next download the project and build the binary file.

$ go get -u -f github.com/esimov/pigo/cmd/pigo
$ go install

Binary releases

Also you can obtain the generated binary files in the releases folder in case you do not have installed or do not want to install Go.

API

Below is a minimal example of using the face detection API.

First you need to load and parse the binary classifier, then convert the image to grayscale mode, and finally to run the cascade function which returns a slice containing the row, column, scale and the detection score.

cascadeFile, err := ioutil.ReadFile("/path/to/cascade/file")
if err != nil {
	log.Fatalf("Error reading the cascade file: %v", err)
}

src, err := pigo.GetImage("/path/to/image")
if err != nil {
	log.Fatalf("Cannot open the image file: %v", err)
}

sampleImg := pigo.RgbToGrayscale(src)

cParams := pigo.CascadeParams{
	MinSize:     1000,
	MaxSize:     20,
	ShiftFactor: 0.1,
	ScaleFactor: 1.1,
}
cols, rows := src.Bounds().Max.X, src.Bounds().Max.Y
imgParams := pigo.ImageParams{sampleImg, rows, cols, cols}

pigo := pigo.NewPigo()
// Unpack the binary file. This will return the number of cascade trees,
// the tree depth, the threshold and the prediction from tree's leaf nodes.
classifier := pigo.Unpack(cascadeFile)

// Run the classifier over the obtained leaf nodes and return the detection results.
// The result contains quadruplets representing the row, column, scale and detection score.
dets := classifier.RunCascade(imgParams, cParams)

// Calculate the intersection over union (IoU) of two clusters.
dets = classifier.ClusterDetections(dets, 0.2)

Usage

A command line utility is bundled into the library to facilitate face detection in static images.

$ pigo -in input.jpg -out out.jpg -cf data/facefinder

Supported flags:

$ pigo --help
┌─┐┬┌─┐┌─┐
├─┘││ ┬│ │
┴  ┴└─┘└─┘

Go (Golang) Face detection library.
    Version: 1.0.1

  -cf string
    	Cascade binary file
  -circle
    	Use circle as detection marker
  -in string
    	Source image
  -iou float
    	Intersection over union (IoU) threshold (default 0.2)
  -max int
    	Maximum size of face (default 1000)
  -min int
    	Minimum size of face (default 20)
  -out string
    	Destination image
  -scale float
    	Scale detection window by percentage (default 1.1)
  -shift float
    	Shift detection window by percentage (default 0.1)

Real time face detection

In case you want to test the library real time face detection capabilities using a webcam there is an example included in the webcam folder. Prior to run it you need to have Pyton2 and OpenCV2 installed. In order to run it select the webcam folder and type:

$ go run main.go -cf "../data/facefinder"

Then access the http://localhost:8081/cam url from a web browser.

Other implementation

https://github.com/tehnokv/picojs

License

Copyright © 2018 Endre Simo

This project is under the MIT License. See the LICENSE file for the full license text.

pigo's People

Contributors

esimov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.