mirror of
https://github.com/esimov/pigo.git
synced 2025-10-06 00:26:50 +08:00
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
// 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 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)
|
|
// }
|
|
|
|
// pixels := pigo.RgbToGrayscale(src)
|
|
// cols, rows := src.Bounds().Max.X, src.Bounds().Max.Y
|
|
|
|
// cParams := pigo.CascadeParams{
|
|
// MinSize: fd.minSize,
|
|
// MaxSize: fd.maxSize,
|
|
// ShiftFactor: fd.shiftFactor,
|
|
// ScaleFactor: fd.scaleFactor,
|
|
|
|
// ImageParams: pigo.ImageParams{
|
|
// Pixels: pixels,
|
|
// Rows: rows,
|
|
// Cols: cols,
|
|
// Dim: 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, err := pigo.Unpack(cascadeFile)
|
|
// if err != nil {
|
|
// log.Fatalf("Error reading the cascade file: %s", err)
|
|
// }
|
|
|
|
// 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.
|
|
package pigo
|