在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Kagami/go-face开源软件地址:https://github.com/Kagami/go-face开源编程语言:Go 52.0%开源软件介绍:go-facego-face implements face recognition for Go using dlib, a popular machine learning toolkit. Read Face recognition with Go article for some background details if you're new to FaceNet concept. RequirementsTo compile go-face you need to have dlib (>= 19.10) and libjpeg development packages installed. Ubuntu 18.10+, Debian sidLatest versions of Ubuntu and Debian provide suitable dlib package so just run: # 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 macOSMake sure you have Homebrew installed. brew install dlib WindowsMake sure you have MSYS2 installed.
Other systemsTry 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. ModelsCurrently wget https://github.com/Kagami/go-face-testdata/raw/master/models/shape_predictor_5_face_landmarks.dat
wget https://github.com/Kagami/go-face-testdata/raw/master/models/dlib_face_recognition_resnet_model_v1.dat
wget https://github.com/Kagami/go-face-testdata/raw/master/models/mmod_human_face_detector.dat UsageTo use go-face in your Go code: import "github.com/Kagami/go-face" To install go-face in your $GOPATH: go get github.com/Kagami/go-face For further details see GoDoc documentation. Examplepackage main
import (
"fmt"
"log"
"path/filepath"
"github.com/Kagami/go-face"
)
// Path to directory with models and test images. Here it's assumed it
// points to the <https://github.com/Kagami/go-face-testdata> clone.
const dataDir = "testdata"
var (
modelsDir = filepath.Join(dataDir, "models")
imagesDir = filepath.Join(dataDir, "images")
)
// This example shows the basic usage of the package: create an
// recognizer, recognize faces, classify them using few known ones.
func main() {
// Init the recognizer.
rec, err := face.NewRecognizer(modelsDir)
if err != nil {
log.Fatalf("Can't init face recognizer: %v", err)
}
// Free the resources when you're finished.
defer rec.Close()
// Test image with 10 faces.
testImagePristin := filepath.Join(imagesDir, "pristin.jpg")
// Recognize faces on that image.
faces, err := rec.RecognizeFile(testImagePristin)
if err != nil {
log.Fatalf("Can't recognize: %v", err)
}
if len(faces) != 10 {
log.Fatalf("Wrong number of faces")
}
// Fill known samples. In the real world you would use a lot of images
// for each person to get better classification results but in our
// example we just get them from one big image.
var samples []face.Descriptor
var cats []int32
for i, f := range faces {
samples = append(samples, f.Descriptor)
// Each face is unique on that image so goes to its own category.
cats = append(cats, int32(i))
}
// Name the categories, i.e. people on the image.
labels := []string{
"Sungyeon", "Yehana", "Roa", "Eunwoo", "Xiyeon",
"Kyulkyung", "Nayoung", "Rena", "Kyla", "Yuha",
}
// Pass samples to the recognizer.
rec.SetSamples(samples, cats)
// Now let's try to classify some not yet known image.
testImageNayoung := filepath.Join(imagesDir, "nayoung.jpg")
nayoungFace, err := rec.RecognizeSingleFile(testImageNayoung)
if err != nil {
log.Fatalf("Can't recognize: %v", err)
}
if nayoungFace == nil {
log.Fatalf("Not a single face on the image")
}
catID := rec.Classify(nayoungFace.Descriptor)
if catID < 0 {
log.Fatalf("Can't classify")
}
// Finally print the classified label. It should be "Nayoung".
fmt.Println(labels[catID])
} Run with: mkdir -p ~/go && cd ~/go # Or cd to your $GOPATH
mkdir -p src/go-face-example && cd src/go-face-example
git clone https://github.com/Kagami/go-face-testdata testdata
edit main.go # Paste example code
go get && go run main.go TestTo fetch test data and run tests: make test FAQHow to improve recognition accuracyThere are few suggestions:
Licensego-face is licensed under CC0. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论