Fix stupid bug with comparing threshold

It was working backwards.

Fixes #33 #16
This commit is contained in:
Kagami Hiiragi
2019-08-18 12:30:04 +03:00
parent ef56f89511
commit 0956e40d34
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -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++;
+2 -2
View File
@@ -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
View File
@@ -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)
}