mirror of
https://github.com/Kagami/go-face.git
synced 2026-04-22 14:57:19 +08:00
Fix stupid bug with comparing threshold
It was working backwards. Fixes #33 #16
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ int classify(
|
||||
int idx = 0;
|
||||
for (const auto& sample : samples) {
|
||||
float dist = dist_func(sample, test_sample);
|
||||
if (dist >= tolerance) {
|
||||
if (tolerance < 0 || dist <= tolerance) {
|
||||
distances.push_back({cats[idx], dist});
|
||||
}
|
||||
idx++;
|
||||
|
||||
@@ -171,8 +171,8 @@ func (rec *Recognizer) Classify(testSample Descriptor) int {
|
||||
return int(C.facerec_classify(rec.ptr, cTestSample, -1))
|
||||
}
|
||||
|
||||
// Same as Classify but allows to specify how much distance between
|
||||
// faces to consider it a match. Start with 0.6 if not sure.
|
||||
// Same as Classify but allows to specify max distance between faces to
|
||||
// consider it a match. Start with 0.6 if not sure.
|
||||
func (rec *Recognizer) ClassifyThreshold(testSample Descriptor, tolerance float32) int {
|
||||
cTestSample := (*C.float)(unsafe.Pointer(&testSample))
|
||||
cTolerance := C.float(tolerance)
|
||||
|
||||
+2
-2
@@ -212,14 +212,14 @@ func TestIdols(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClassifyThreshold(t *testing.T) {
|
||||
id, err := recognizeAndClassify(getTPath("nana.jpg"), 0.8)
|
||||
id, err := recognizeAndClassify(getTPath("nana.jpg"), 0.1)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't recognize: %v", err)
|
||||
}
|
||||
if id >= 0 {
|
||||
t.Fatalf("Shouldn't recognize but got %d category", id)
|
||||
}
|
||||
id, err = recognizeAndClassify(getTPath("nana.jpg"), 0.1)
|
||||
id, err = recognizeAndClassify(getTPath("nana.jpg"), 0.8)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't recognize: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user