tinyface

package module
v0.0.0-...-6223c44 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 14 Imported by: 0

README

tinyface

a tiny go- face based face recongnition lib

Requirements

tinyface require go-face to compile. go-face need to have dlib (>= 19.10) and libjpeg development packages installed.

Ubuntu 18.10+, Debian sid Latest versions of Ubuntu and Debian provide suitable dlib package so just run:

Arch
sudo pacman -S dlib blas atlas lapack libjpeg-turbo
Ubuntu
sudo apt-get install libdlib-dev libblas-dev libatlas-base-dev liblapack-dev libjpeg-turbo8-dev
Debian
sudo apt-get install libdlib-dev libblas-dev libatlas-base-dev liblapack-dev libjpeg62-turbo-dev
macOS

Make sure you have Homebrew installed.

brew install dlib
Windows

Make sure you have MSYS2 installed.

  1. Run MSYS2 MSYS shell from Start menu
  2. Run pacman -Syu and if it asks you to close the shell do that
  3. Run pacman -Syu again
  4. Run pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-dlib
  5. If you already have Go and Git installed and available in PATH uncomment set MSYS2_PATH_TYPE=inherit line in msys2_shell.cmd located in MSYS2 installation folder,Otherwise run pacman -S mingw-w64-x86_64-go git
  6. Run MSYS2 MinGW 64-bit shell from Start menu to compile and use go-face
Other systems

Try to install dlib/libjpeg with package manager of your distribution or compile from sources. Note that go-face won't work with old packages of dlib such as libdlib18. Alternatively create issue with the name of your system and someone might help you with the installation process.

reference

Models

Currently shape_predictor_5_face_landmarks.dat, mmod_human_face_detector.dat and dlib_face_recognition_resnet_model_v1.dat are required. You may download them from dlib-models repo:

mkdir models && cd models
wget https://github.com/davisking/dlib-models/raw/master/shape_predictor_5_face_landmarks.dat.bz2
bunzip2 shape_predictor_5_face_landmarks.dat.bz2
wget https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2
bunzip2 dlib_face_recognition_resnet_model_v1.dat.bz2
wget https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2
bunzip2 mmod_human_face_detector.dat.bz2

you can also use go-face 's testdata repo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ModelPathNotAvailableError = errors.New("the model is not available")

	NoFaceOnImageError         = errors.New("no face on the image")
	NotASingleFaceOnImageError = errors.New("not a single face on the image")
)

Functions

This section is empty.

Types

type Face

type Face struct {
	*SampleBaseData
	Rectangle image.Rectangle
}

Face holds coordinates and descriptor of the human face.

type Option

type Option func(recognizer *Recognizer)

func UseCNN

func UseCNN(useCNN bool) Option

UseCNN set whether to use CNN or not.

func UseGray

func UseGray(useGray bool) Option

UseGray set whether to use grayscale or not.

func WithModelPath

func WithModelPath(modelPath string) Option

WithModelPath sets the path to the model directory.

func WithSamplesLoader

func WithSamplesLoader(loader SamplesLoader) Option

WithSamplesLoader sets the samples loader.

func WithSamplesSaver

func WithSamplesSaver(saver SamplesSaver) Option

WithSamplesSaver sets the dataSet store method

func WithTolerance

func WithTolerance(tolerance float32) Option

WithTolerance sets the tolerance for the recognition.

type Recognizer

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

func NewRecognizer

func NewRecognizer(opts ...Option) (*Recognizer, error)

func (*Recognizer) AddImageToSamples

func (r *Recognizer) AddImageToSamples(filePath string, Id string) error

AddImageToSamples add a sample image to the samples

func (*Recognizer) Classify

func (r *Recognizer) Classify(Path string) ([]*Face, error)

Classify returns all faces identified in the image. Empty list is returned if no match.

func (*Recognizer) ClassifyMultiples

func (r *Recognizer) ClassifyMultiples(Path string) ([]Face, error)

ClassifyMultiples returns all faces identified in the image. Empty list is returned if no match.

func (*Recognizer) Close

func (r *Recognizer) Close()

Close frees resources taken by the Recognizer. Safe to call multiple times. Don't use Recognizer after close call.

func (*Recognizer) DrawFaces

func (r *Recognizer) DrawFaces(Path string, F []Face) (image.Image, error)

DrawFaces draws the faces identified in the original image

func (*Recognizer) DrawFaces2

func (r *Recognizer) DrawFaces2(Path string, F []goFace.Face) (image.Image, error)

DrawFaces2 draws the faces in the original image

func (*Recognizer) GrayScale

func (r *Recognizer) GrayScale(imgSrc image.Image) image.Image

GrayScale Convert an image to grayscale

func (*Recognizer) LoadImage

func (r *Recognizer) LoadImage(Path string) (image.Image, error)

LoadImage Load an image from file

func (*Recognizer) LoadSamples

func (r *Recognizer) LoadSamples(samplesPath ...string) error

LoadSamples load samples using config loader

func (*Recognizer) RecognizeMultiples

func (r *Recognizer) RecognizeMultiples(Path string) ([]goFace.Face, error)

RecognizeMultiples returns all faces found on the provided image, sorted from left to right. Empty list is returned if there are no faces, error is returned if there was some error while decoding/processing image. Only JPEG format is currently supported.

func (*Recognizer) RecognizeSingle

func (r *Recognizer) RecognizeSingle(Path string) (*goFace.Face, error)

RecognizeSingle returns face if it's the only face on the image or nil otherwise. Only JPEG format is currently supported.

func (*Recognizer) SaveSamples

func (r *Recognizer) SaveSamples(samplesPath ...string) error

SaveSamples save samples using config saver

func (*Recognizer) SaveToJpeg

func (r *Recognizer) SaveToJpeg(Path string, img image.Image) error

SaveToJpeg Save an image to jpeg file

type SampleBaseData

type SampleBaseData struct {
	Id         string
	Descriptor goFace.Descriptor
}

SampleBaseData descriptor of the human face.

type SamplesLoader

type SamplesLoader interface {
	LoadSamples(dataSetPath ...string) ([]*SampleBaseData, error)
}

SamplesLoader is the interface for loading a dataset.

type SamplesSaver

type SamplesSaver interface {
	SaveSamples(dataSet []*SampleBaseData, dataSetPath ...string) error
}

SamplesSaver is the interface for storing a dataset.

Jump to

Keyboard shortcuts

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