- libtensorfow 1.x Follow the instruction Install TensorFlow for C
- facenet tenorflow saved_model Google Drive
- build the executable
- download font(optional) Google Drive
# generated to ./bin/facenet
make facenetgo get -u github.com/bububa/facenet
./bin/facenet -model=./models/facenet -db=./models/people.db -train={image folder for training} -output={fold path for output thumbs(optional)}the train folder include folders which name is the label with images inside
./bin/facenet -model=./models/facenet -db=./models/people.db -update={labels for update seperated by comma} -output={fold path for output thumbs(optional)}./bin/facenet -model=./models/facenet -db=./models/people.db -delete={labels for delete seperated by comma} -output={fold path for output thumbs(optional)}./bin/facenet -model=./models/facenet -db=./models/people.db -detect={the image file path for detecting} -font={font folder for output image(optional)} -output={fold path for output thumbs(optional)}- libjpeg-turbo (use
-tags jpegto build withoutCGo) - On Linux/RPi native Go V4L implementation is used to capture images.
make cvcamera# use native Go V4L implementation is used to capture images
make linux_camerause jpeg build tag to build with native Go image/jpeg instead of libjpeg-turbo
go build -o=./bin/cvcamera -tags=cv4,jpeg ./cmd/cameraUsage of camera:
-bind string
Bind address (default ":56000")
-delay int
Delay between frames, in milliseconds (default 10)
-width float
Frame width (default 640)
-height float
Frame height (default 480)
-index int
Camera index
-model string
saved_mode path
-db string
classifier db
import (
"log""github.com/llgcode/draw2d""github.com/bububa/facenet"
)
funcmain() {
estimator, err:=facenet.New(
facenet.WithModel("./models/facenet"),
facenet.WithDB("./models/people.db"),
facenet.WithFontPath("./font"),
)
iferr!=nil {
log.Fatalln(err)
}
err=estimator.SetFont(&draw2d.FontData{
Name: "NotoSansCJKsc",
//Name: "Roboto",Family: draw2d.FontFamilySans,
Style: draw2d.FontStyleNormal,
}, 9)
iferr!=nil {
log.Fatalln(err)
}
// Delete labels
{
labels:= []string{"xxx", "yyy"}
for_, label:=rangelabels {
ifdeleted:=estimator.DeletePerson(label); deleted {
log.Printf("[INFO] person: %s deleted\n", label)
continue
}
log.Printf("[WRN] person: %s not found\n", label)
}
err:=estimator.SaveDB("./models/people.db")
iferr!=nil {
log.Fatalln(err)
}
}
// Detect faces
{
img, _:=loadImage(imgPath)
minSize:=20markers, err:=instance.DetectFaces(img, minSize)
iferr!=nil {
log.Fatalln(err)
}
for_, marker:=rangemarkers.Markers() {
ifmarker.Error() !=nil {
log.Printf("label: %s, %v\n", marker.Label(), marker.Error())
} else {
log.Printf("label: %s, distance:%f\n", marker.Label(), marker.Distance())
}
}
ifoutputPath!="" {
txtColor:="#FFF"successColor:="#4CAF50"failedColor:="#F44336"strokeWidth:=2successMarkerOnly:=falsemarkerImg:=estimator.DrawMarkers(markers, txtColor, successColor, failedColor, 2, successMarkerOnly)
iferr:=saveImage(markerImg, outputPath); err!=nil {
log.Fatalln(err)
}
}
}
// Training// check cmd/facenet
}