core

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package core facenet core module

Index

Constants

This section is empty.

Variables

View Source
var ClusterCore = 4

ClusterCore depreciated

View Source
var ClusterDist = 0.64

ClusterDist default cluster distance

View Source
var ClusterMinScore = 15

ClusterMinScore depreciated

View Source
var ClusterMinSize = 95

ClusterMinSize depreciated

CropSize default crop size for image

View Source
var File_core_person_proto protoreflect.FileDescriptor
View Source
var MatchDist = 0.46

MatchDist default match distance

View Source
var MaxImageSize = 640

MaxImageSize defines maxium image size for detection resize

View Source
var OverlapThreshold = 42

OverlapThreshold default face overlap threshold

View Source
var OverlapThresholdFloor = OverlapThreshold - 1

OverlapThresholdFloor default face overlap threshold floor

View Source
var SampleThreshold = 2 * ClusterCore

SampleThreshold depreciated

View Source
var ScoreThreshold = 4.0

ScoreThreshold default quality threshold score

Functions

func EuclideanDistance

func EuclideanDistance(face1 []float32, face2 []float32) float64

EuclideanDistance calculate euclidean distance between to vectors

func LoadPeople

func LoadPeople(r io.Reader, people *People) error

LoadPeople load people model

func QualityThreshold

func QualityThreshold(scale int) (score float32)

QualityThreshold returns the scale adjusted quality score threshold.

func ReadCascadeDir

func ReadCascadeDir(plc *pigo.PuplocCascade, path string) (result map[string][]*FlpCascade, err error)

ReadCascadeDir reads the facial landmark points cascade files from the provided directory.

Types

type Area

type Area struct {
	Name  string `json:"name,omitempty"`
	Row   int    `json:"x,omitempty"`
	Col   int    `json:"y,omitempty"`
	Scale int    `json:"size,omitempty"`
}

Area represents a face landmark position.

func NewArea

func NewArea(name string, row, col, scale int) Area

NewArea returns new face landmark coordinates.

func (Area) Relative

func (a Area) Relative(r Area, rows, cols float32) imageutil.Area

Relative returns the area with relative coordinates.

func (Area) String

func (a Area) String() string

String returns the face landmark position as string.

func (Area) TopLeft

func (a Area) TopLeft() (int, int)

TopLeft returns the top left position of the area.

type Areas

type Areas []Area

Areas is a list of face landmark areas.

func (Areas) Relative

func (pts Areas) Relative(r Area, rows, cols float32) (result imageutil.Areas)

Relative returns all areas with relative coordinates.

type ErrCode

type ErrCode int

ErrCode error code

const (
	// UnknownErr unknown error code
	UnknownErr ErrCode = iota
	// ExtractImageSizeTooSmallErr extract image size is too small
	ExtractImageSizeTooSmallErr
	// NoFaceErr no face detected error
	NoFaceErr
	// InferenceFailedErr extract face failed
	InferenceFailedErr
	// ImageToTensorSizeErr convert image to tensor size error
	ImageToTensorSizeErr
	// NegativeDistanceMatchErr match distance is negative
	NegativeDistanceMatchErr
	// TooFarMatchErr match distance is too far
	TooFarMatchErr
	// CollisionMatchErr match distance is larger than collision radius, may need more trainning data
	CollisionMatchErr
	// NothingMatchErr represents nothing matched
	NothingMatchErr
	// UnknownClassifierErr represents met an unknown classifier in saved db
	UnknownClassifierErr
)

type Error

type Error struct {
	// Code error code
	Code ErrCode `json:"code,omitempty"`
	// Msg error message
	Msg string `json:"msg,omitempty"`
}

Error custom error object

func NewError

func NewError(code ErrCode, msg string) Error

NewError create an error

func (Error) Error

func (e Error) Error() string

Error implement error interface

type Extractor

type Extractor struct {
	// contains filtered or unexported fields
}

Extractor struct contains Pigo face detector general settings.

func (*Extractor) Extract

func (d *Extractor) Extract(img image.Image) (faces []pigo.Detection, params pigo.CascadeParams, err error)

Extract runs the detection algorithm over the provided source image.

func (*Extractor) Faces

func (d *Extractor) Faces(det []pigo.Detection, params pigo.CascadeParams, findLandmarks bool) (results Faces, err error)

Faces adds landmark coordinates to detected faces and returns the results.

type Face

type Face struct {
	Rows       int         `json:"rows,omitempty"`
	Cols       int         `json:"cols,omitempty"`
	Score      int         `json:"score,omitempty"`
	Area       Area        `json:"face,omitempty"`
	Eyes       Areas       `json:"eyes,omitempty"`
	Landmarks  Areas       `json:"landmarks,omitempty"`
	Embeddings [][]float32 `json:"embeddings,omitempty"`
}

Face represents a face detected.

func TrySizeExtractSingle

func TrySizeExtractSingle(img image.Image, findLandmarks bool, minSize int) (face Face, err error)

TrySizeExtractSingle extract single face with different minSize

func (*Face) CropArea

func (f *Face) CropArea() imageutil.Area

CropArea returns the relative image area for cropping.

func (*Face) Dim

func (f *Face) Dim() float32

Dim returns the max number of rows and cols as float32 to calculate relative coordinates.

func (*Face) EmbeddingsJSON

func (f *Face) EmbeddingsJSON() (b []byte)

EmbeddingsJSON returns detected face embeddings as JSON array.

func (*Face) EyesMidpoint

func (f *Face) EyesMidpoint() Area

EyesMidpoint returns the point in between the eyes.

func (*Face) RelativeLandmarks

func (f *Face) RelativeLandmarks() imageutil.Areas

RelativeLandmarks returns relative face areas.

func (*Face) RelativeLandmarksJSON

func (f *Face) RelativeLandmarksJSON() (b []byte)

RelativeLandmarksJSON returns relative face areas as JSON.

func (*Face) Size

func (f *Face) Size() int

Size returns the absolute face size in pixels.

type FaceMarker

type FaceMarker struct {
	// contains filtered or unexported fields
}

FaceMarker detected face

func NewFaceMarker

func NewFaceMarker(face Face, label string, distance float64) *FaceMarker

NewFaceMarker init a FaceMarker

func (FaceMarker) Bounds

func (f FaceMarker) Bounds(img image.Image) image.Rectangle

Bounds FackeMarker image bounds

func (FaceMarker) Distance

func (f FaceMarker) Distance() float64

Distance get marker distance

func (FaceMarker) Error

func (f FaceMarker) Error() error

Error identify the successful of matching

func (FaceMarker) Face

func (f FaceMarker) Face() Face

Face get marker face

func (FaceMarker) Label

func (f FaceMarker) Label() string

Label get marker label

func (*FaceMarker) SetError

func (f *FaceMarker) SetError(err error)

SetError set face maker match failed

func (FaceMarker) Thumb

func (f FaceMarker) Thumb(img image.Image) image.Image

Thumb generate thumb image of a face marker

type FaceMarkers

type FaceMarkers struct {
	// contains filtered or unexported fields
}

FaceMarkers image detected with markers

func NewFaceMarkers

func NewFaceMarkers(img image.Image) *FaceMarkers

NewFaceMarkers init face markers

func (*FaceMarkers) Append

func (fm *FaceMarkers) Append(m FaceMarker)

Append append FaceMarker to FaceMarkers

func (FaceMarkers) Draw

func (fm FaceMarkers) Draw(font *imageutil.Font, txtColor string, successColor string, failedColor string, strokeWidth float64, succeedOnly bool) image.Image

Draw draw face markers on image

func (*FaceMarkers) FaceImages

func (fm *FaceMarkers) FaceImages(img image.Image) []image.Image

FaceImages get face images from face markers

func (*FaceMarkers) Markers

func (fm *FaceMarkers) Markers() []FaceMarker

Markers get markers

type Faces

type Faces []Face

Faces represents a list of faces detected.

func Extract

func Extract(img image.Image, findLandmarks bool, minSize int) (faces Faces, err error)

Extract runs the detection algorithm over the provided source image.

func NewFaces added in v1.0.1

func NewFaces(cap int) Faces

NewFaces init faces with cap

func TrySizeExtractMultiple

func TrySizeExtractMultiple(img image.Image, findLandmarks bool, minSize int) (faces Faces, err error)

TrySizeExtractMultiple extract multiple faces with different minSize

func (*Faces) Append

func (faces *Faces) Append(f Face)

Append adds a face.

func (Faces) Contains

func (faces Faces) Contains(other Face) bool

Contains returns true if the face conflicts with existing faces.

func (Faces) Count

func (faces Faces) Count() int

Count returns the number of faces detected.

func (Faces) Uncertainty

func (faces Faces) Uncertainty() int

Uncertainty return the max face detection uncertainty in percent.

type FlpCascade

type FlpCascade struct {
	*pigo.PuplocCascade
	// contains filtered or unexported fields
}

FlpCascade holds the binary representation of the facial landmark points cascade files

type Net

type Net struct {
	// contains filtered or unexported fields
}

Net is a wrapper for the TensorFlow Facenet model.

func NewNet

func NewNet(modelPath string) *Net

NewNet returns a new TensorFlow Facenet instance.

func (*Net) Detect

func (t *Net) Detect(img image.Image, minSize int, expected int) (faces Faces, err error)

Detect runs the detection and facenet algorithms over the provided source image.

func (*Net) DetectMultiple

func (t *Net) DetectMultiple(img image.Image, minSize int) (faces Faces, err error)

DetectMultiple detect multiple faces try to use different minSize

func (*Net) DetectSingle

func (t *Net) DetectSingle(img image.Image, minSize int) (face Face, err error)

DetectSingle detect single face try to use different minSize

func (*Net) LoadModel added in v1.1.0

func (t *Net) LoadModel() error

func (*Net) ModelLoaded

func (t *Net) ModelLoaded() bool

ModelLoaded tests if the TensorFlow model is loaded.

func (*Net) Train

func (t *Net) Train(label string, images []image.Image, minSize int) (person Person, err error)

Train train images with label defined

type People

type People struct {
	List []*Person `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"`
	// contains filtered or unexported fields
}

func (*People) Append

func (people *People) Append(items ...*Person)

Append append person to people and update when duplicate

func (*People) Delete

func (people *People) Delete(name string) bool

Delete delete a person from people

func (*People) Descriptor deprecated

func (*People) Descriptor() ([]byte, []int)

Deprecated: Use People.ProtoReflect.Descriptor instead.

func (*People) GetList

func (x *People) GetList() []*Person

func (*People) Match

func (people *People) Match(embedding []float32) (*Person, float64, error)

Match match a person from people based on embedding

func (*People) Nearest

func (people *People) Nearest(embedding []float32) (*Person, float64)

Nearest returns nearest person in people

func (*People) Neighbour

func (people *People) Neighbour(embedding []float32, nearest *Person) (*Person, float64)

Neighbour returns neighbour person in people

func (*People) ProtoMessage

func (*People) ProtoMessage()

func (*People) ProtoReflect

func (x *People) ProtoReflect() protoreflect.Message

func (*People) Reset

func (x *People) Reset()

func (*People) ResolveCollisions

func (people *People) ResolveCollisions()

ResolveCollisions resolves collisions of different subject's faces.

func (*People) Save

func (people *People) Save(w io.Writer) error

Save save people to a model file

func (*People) Setup

func (people *People) Setup()

Setup recalculate people's center and collisions

func (*People) String

func (x *People) String() string

type Person

type Person struct {
	Name            string              `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Embeddings      []*Person_Embedding `protobuf:"bytes,2,rep,name=embeddings,proto3" json:"embeddings,omitempty"`
	Center          []float32           `protobuf:"fixed32,3,rep,packed,name=center,proto3" json:"center,omitempty"`
	Radius          float64             `protobuf:"fixed64,4,opt,name=radius,proto3" json:"radius,omitempty"`
	CollisionRadius float64             `protobuf:"fixed64,5,opt,name=collision_radius,json=collisionRadius,proto3" json:"collision_radius,omitempty"`
	// contains filtered or unexported fields
}

func (*Person) Append

func (person *Person) Append(embedding []float32)

Append append embedding to person

func (*Person) AverageDistance

func (person *Person) AverageDistance(embedding []float32) float64

AverageDistance returns the average distance between o and all people

func (*Person) CalcCenter

func (person *Person) CalcCenter() (result []float32, radius float64, count int)

CalcCenter returns the center coordinates of a set of people

func (*Person) Descriptor deprecated

func (*Person) Descriptor() ([]byte, []int)

Deprecated: Use Person.ProtoReflect.Descriptor instead.

func (*Person) Equal

func (person *Person) Equal(another *Person) bool

Equal check two person are equal

func (*Person) GetCenter

func (x *Person) GetCenter() []float32

func (*Person) GetCollisionRadius

func (x *Person) GetCollisionRadius() float64

func (*Person) GetEmbeddings

func (x *Person) GetEmbeddings() []*Person_Embedding

func (*Person) GetName

func (x *Person) GetName() string

func (*Person) GetRadius

func (x *Person) GetRadius() float64

func (*Person) Match

func (person *Person) Match(embedding []float32) (bool, float64)

Match match embedding with a person

func (*Person) ProtoMessage

func (*Person) ProtoMessage()

func (*Person) ProtoReflect

func (x *Person) ProtoReflect() protoreflect.Message

func (*Person) ReCenter

func (person *Person) ReCenter()

ReCenter recalculate person's center

func (*Person) Reset

func (x *Person) Reset()

func (*Person) ResolveCollision

func (person *Person) ResolveCollision(p2 *Person)

ResolveCollision calculate CollisionRadius for a person

func (*Person) String

func (x *Person) String() string

type Person_Embedding

type Person_Embedding struct {
	Value []float32 `protobuf:"fixed32,1,rep,packed,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*Person_Embedding) Descriptor deprecated

func (*Person_Embedding) Descriptor() ([]byte, []int)

Deprecated: Use Person_Embedding.ProtoReflect.Descriptor instead.

func (*Person_Embedding) GetValue

func (x *Person_Embedding) GetValue() []float32

func (*Person_Embedding) ProtoMessage

func (*Person_Embedding) ProtoMessage()

func (*Person_Embedding) ProtoReflect

func (x *Person_Embedding) ProtoReflect() protoreflect.Message

func (*Person_Embedding) Reset

func (x *Person_Embedding) Reset()

func (*Person_Embedding) String

func (x *Person_Embedding) String() string

Jump to

Keyboard shortcuts

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