You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering an error when running the library's example code. In it, we import an image with 10 faces, then we import an image with another face and the system classifies it. The problem I'm encountering is precisely when I import an image of a face that isn't in the original photo, with 10 people. The classification system should return an index less than 0 according to the documentation, but this is not the behavior. It always returns a real index.
When using an image of Obama, the system output is Yuha
package 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.constdataDir="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.funcmain() {
// Init the recognizer.rec, err:=face.NewRecognizer(modelsDir)
iferr!=nil {
log.Fatalf("Can't init face recognizer: %v", err)
}
// Free the resources when you're finished.deferrec.Close()
// Test image with 10 faces.testImagePristin:=filepath.Join(imagesDir, "pristin.jpg")
// Recognize faces on that image.faces, err:=rec.RecognizeFile(testImagePristin)
iferr!=nil {
log.Fatalf("Can't recognize: %v", err)
}
iflen(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.varsamples []face.Descriptorvarcats []int32fori, f:=rangefaces {
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.unknownImage:=filepath.Join(imagesDir, "obama.jpg")
unknownFace, err:=rec.RecognizeSingleFile(unknownImage)
iferr!=nil {
log.Fatalf("Can't recognize: %v", err)
}
ifunknownFace==nil {
log.Fatalf("Not a single face on the image")
}
catID:=rec.Classify(unknownFace.Descriptor)
ifcatID<0 {
log.Fatalf("Can't classify")
}
fmt.Println(labels[catID])
}
The text was updated successfully, but these errors were encountered:
I'm encountering an error when running the library's example code. In it, we import an image with 10 faces, then we import an image with another face and the system classifies it. The problem I'm encountering is precisely when I import an image of a face that isn't in the original photo, with 10 people. The classification system should return an index less than 0 according to the documentation, but this is not the behavior. It always returns a real index.
When using an image of Obama, the system output is Yuha
The text was updated successfully, but these errors were encountered: