pigo

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeImage

func DecodeImage(f io.Reader) (*image.NRGBA, error)

DecodeImage decodes the image file to *image.NRGBA type.

func GetImage

func GetImage(input string) (*image.NRGBA, error)

GetImage retrieves and decodes the image file to *image.NRGBA type.

func ImgToNRGBA

func ImgToNRGBA(img image.Image) *image.NRGBA

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

func RgbToGrayscale(src image.Image) []uint8

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

type Detection struct {
	Row   int
	Col   int
	Scale int
	Q     float32
}

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

type ImageParams struct {
	Pixels []uint8
	Rows   int
	Cols   int
	Dim    int
}

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

func (p *Pigo) ClusterDetections(detections []Detection, iouThreshold float64) []Detection

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL