Documentation
¶
Overview ¶
Package pigo is a lightweight pure Go face detection, pupil/eyes localization and facial landmark points detection library based on Pixel Intensity Comparison-based Object detection paper (https://arxiv.org/pdf/1305.4537.pdf). Is platform agnostic and does not require any external dependencies and third party modules.
Face detection API example.
First the source image should be converted to grayscale mode, then the cascade function can be invoked, which returns a slice containing the row, column, the scale and the detection score.
src, err := pigo.GetImage("/path/to/image")
if err != nil {
log.Fatalf("Cannot open the image file: %v", err)
}
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,
ImageParams: pigo.ImageParams{
Pixels: pixels,
Rows: rows,
Cols: cols,
Dim: cols,
},
}
// Unpack the facefinder 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()
angle := 0.0 // cascade rotation angle. 0.0 is 0 radians and 1.0 is 2*pi radians
// 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(cParams, angle)
// Calculate the intersection over union (IoU) of two clusters.
dets = classifier.ClusterDetections(dets, 0.2)
For pupil/eyes localization and facial landmark points detection API example check the source code.
Index ¶
- func DecodeImage(f io.Reader) (*image.NRGBA, error)
- func GetImage(input string) (*image.NRGBA, error)
- func ImgToNRGBA(img image.Image) *image.NRGBA
- func ReadFlpCascadeDir() (map[string][]*FlpCascade, error)
- func RgbToGrayscale(src image.Image) []uint8
- type CascadeParams
- type Detection
- type FlpCascade
- type ImageParams
- type Pigo
- type Puploc
- type PuplocCascade
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeImage ¶
DecodeImage decodes the image file to *image.NRGBA type.
func ImgToNRGBA ¶
ImgToNRGBA converts any image type to *image.NRGBA with min-point at (0, 0).
func ReadFlpCascadeDir ¶ added in v1.5.1
func ReadFlpCascadeDir() (map[string][]*FlpCascade, error)
ReadFlpCascadeDir reads the directory of the embedded facial landmark points cascade files and extracts their content.
func RgbToGrayscale ¶
RgbToGrayscale converts the image to grayscale mode.
Types ¶
type CascadeParams ¶
type CascadeParams struct {
ImageParams
MinSize int
MaxSize int
ShiftFactor float64
ScaleFactor float64
}
CascadeParams contains the basic parameters to run the analyzer function over the defined image. MinSize: represents the minimum size of the face. MaxSize: represents the maximum size of the face. ShiftFactor: determines to what percentage to move the detection window over its size. ScaleFactor: defines in percentage the resize value of the detection window when moving to a higher scale.
type Detection ¶
Detection struct contains the detection results composed of the row, column, scale factor and the detection score.
type FlpCascade ¶
type FlpCascade struct {
*PuplocCascade
}
FlpCascade holds the binary representation of the facial landmark points cascade files.
type ImageParams ¶
ImageParams is a struct for image related settings. Pixels: contains the grayscale converted image pixel data. Rows: the number of image rows. Cols: the number of image columns. Dim: the image dimension.
type Pigo ¶
type Pigo struct {
// contains filtered or unexported fields
}
Pigo struct defines the basic binary tree components.
func UnpackCascade ¶ added in v1.5.1
func UnpackCascade() *Pigo
UnpackCascade unpack the embedded facefinder binary file. This will return the number of cascade trees, the tree depth, the threshold and the prediction from tree's leaf nodes.
func (*Pigo) ClusterDetections ¶
ClusterDetections returns the intersection over union of multiple clusters. We need to make this comparison to filter out multiple face detection regions.
func (*Pigo) RunClassifier ¶ added in v1.5.1
func (p *Pigo) RunClassifier(cp *CascadeParams, faceAngle float64) []Detection
RunClassifier analyze the grayscale converted image pixel data and run the classification function over the detection window. It will return a slice containing the detection row, column, it's center and the detection score (in case this is greater than 0.0).
type Puploc ¶
type Puploc struct {
Row int
Col int
Scale float32
// The detector might produce certain overlapping results,
// due to the small perturbations in position and scale.
// This value defines how many times a detection should be
// performed over the quasi identical overlapping results.
Perturbs int
}
Puploc is used to gather all the relevant information resulted from the pupil detection.
type PuplocCascade ¶
type PuplocCascade struct {
// contains filtered or unexported fields
}
PuplocCascade is a general struct for storing the cascade tree values encoded into the binary file.
func UnpackPlc ¶ added in v1.5.1
func UnpackPlc() (*PuplocCascade, error)
UnpackPlc reads and unpack the embedded pupil localization (puploc) cascade file. Returns error in case of failure on reading the embedded file.
func (*PuplocCascade) LandmarkPoint ¶
func (plc *PuplocCascade) LandmarkPoint(leftEye, rightEye *Puploc, img *ImageParams, perturb int, flipV bool) *Puploc
LandmarkPoint calculates the facial landmark point position based on the eyes localization results.
func (*PuplocCascade) RunClassifier ¶ added in v1.5.1
func (plc *PuplocCascade) RunClassifier(pl *Puploc, img *ImageParams, faceAngle float64, flipV bool) *Puploc
RunClassifier runs the pupil localization function.