diff --git a/classify.cc b/classify.cc index d9a914b..539ca57 100644 --- a/classify.cc +++ b/classify.cc @@ -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++; diff --git a/face.go b/face.go index 1f959e7..2681188 100644 --- a/face.go +++ b/face.go @@ -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) diff --git a/face_test.go b/face_test.go index bb24020..2b073f3 100644 --- a/face_test.go +++ b/face_test.go @@ -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) }