Skip to content

Commit 7817c13

Browse files
author
Leandro
committed
examples: demonstrate ErrNotSingleFace in the landmarks example
RecognizeSingle genuinely returns ErrNotSingleFace (unlike RecognizeMultiples/IdentifyMultiples, which return an empty/partial list instead of erroring), so it's worth showing the errors.Is check here too.
1 parent aec4919 commit 7817c13

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func main() {
284284
package main
285285

286286
import (
287+
"errors"
287288
"fmt"
288289
"path/filepath"
289290

@@ -311,7 +312,11 @@ func main() {
311312

312313
f, err := rec.RecognizeSingle(filepath.Join(fotosDir, "amy.jpg"))
313314

314-
if err != nil {
315+
switch {
316+
case errors.Is(err, recognizer.ErrNotSingleFace):
317+
fmt.Println("amy.jpg doesn't have exactly one face")
318+
return
319+
case err != nil:
315320
fmt.Println(err)
316321
return
317322
}

examples/landmarks/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"path/filepath"
67

@@ -28,7 +29,11 @@ func main() {
2829

2930
f, err := rec.RecognizeSingle(filepath.Join(fotosDir, "amy.jpg"))
3031

31-
if err != nil {
32+
switch {
33+
case errors.Is(err, recognizer.ErrNotSingleFace):
34+
fmt.Println("amy.jpg doesn't have exactly one face")
35+
return
36+
case err != nil:
3237
fmt.Println(err)
3338
return
3439
}

0 commit comments

Comments
 (0)