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
Browse filesBrowse the repository at this point in the historyBrowse files
Leandro
committed
Rename Classify to Identify/IdentifyMultiples; add sentinel errors
Aligns with go-face's Identify/IdentifyThreshold rename (breaking, no
alias) and biometric terminology (Detect -> Recognize -> Compare ->
Identify).
Also replaces string-matched error messages with exported sentinel
errors (ErrNoFace, ErrNotSingleFace, ErrNoMatch, ErrDatasetFileNotFound)
checkable via errors.Is, and fixes a stale doc comment on Identify that
claimed it returns an empty list on no match (it returns ErrNoMatch).
Requires go-face v1.1.0.
@@ -340,6 +344,36 @@ face-descriptor (ResNet) and CNN detector model files respectively —
340
344
useful if you're using differently-named or fine-tuned dlib models. All
341
345
three must be set before calling `Init`; they're read once, at load time.
342
346
347
+
## Errors
348
+
349
+
The "expected" failure conditions -- no face detected, more than one
350
+
face detected, no dataset match, a missing dataset file -- are exposed
351
+
as sentinel errors, so callers can branch on them with `errors.Is`
352
+
instead of matching on the error message text (which isn't part of the
353
+
API contract and may change):
354
+
355
+
```go
356
+
faces, err:= rec.Identify(path)
357
+
switch {
358
+
case errors.Is(err, recognizer.ErrNotSingleFace):
359
+
// the image doesn't have exactly one face
360
+
case errors.Is(err, recognizer.ErrNoMatch):
361
+
// no Dataset entry within Tolerance
362
+
case err != nil:
363
+
// something else went wrong (I/O, decode, ...)
364
+
}
365
+
```
366
+
367
+
| Error | Returned by |
368
+
|-------|-------------|
369
+
|`ErrNoFace`|`AddImageToDataset`, when the image has no detected face |
370
+
|`ErrNotSingleFace`|`AddImageToDataset`, `RecognizeSingle`, `Identify`, when the image has more than one detected face (or, for `RecognizeSingle`/`Identify`, doesn't have exactly one) |
371
+
|`ErrNoMatch`|`Identify`, when the face doesn't match any `Dataset` entry within `Tolerance`|
372
+
|`ErrDatasetFileNotFound`|`LoadDataset`, when `Path` doesn't exist |
373
+
374
+
Any other error (I/O, image decoding, etc.) is wrapped with `%w`, so
375
+
`errors.Unwrap`/`errors.As` still reach the underlying cause.
376
+
343
377
## Contributing
344
378
345
379
Issues and pull requests are welcome. If you're reporting a build problem,
0 commit comments