forked from GoogleCloudPlatform/golang-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (60 loc) · 1.81 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2017 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// Command detect uses the Vision API's label detection capabilities to find a label based on an image's content.
package main
import (
"flag"
"fmt"
"io"
"os"
"path/filepath"
"strings"
)
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s <path-to-image>\n", filepath.Base(os.Args[0]))
fmt.Fprintf(os.Stderr, "Pass either a path to a local file, or a URI.\n")
fmt.Fprintf(os.Stderr, "Prefix a path with gs:// to refer to a file on GCS.\n")
}
flag.Parse()
args := flag.Args()
if len(args) == 0 {
flag.Usage()
os.Exit(1)
}
path := flag.Arg(0)
match := flag.Arg(1)
samples := []struct {
name string
local, uri func(io.Writer, string) error
}{
{"detectFaces", detectFaces, detectFacesURI},
{"detectLabels", detectLabels, detectLabelsURI},
{"detectLandmarks", detectLandmarks, detectLandmarksURI},
{"detectText", detectText, detectTextURI},
{"detectDocumentText", detectDocumentText, detectDocumentTextURI},
{"detectLogos", detectLogos, detectLogosURI},
{"detectProperties", detectProperties, detectPropertiesURI},
{"detectCropHints", detectCropHints, detectCropHintsURI},
{"detectWeb", detectWeb, detectWebURI},
{"detectWebGeo", detectWebGeo, detectWebGeoURI},
{"detectSafeSearch", detectSafeSearch, detectSafeSearchURI},
{"localizeObjects", localizeObjects, localizeObjectsURI},
}
for _, sample := range samples {
if !strings.Contains(sample.name, match) {
continue
}
fmt.Println("---", sample.name)
var err error
if strings.Contains(path, "://") {
err = sample.uri(os.Stdout, path)
} else {
err = sample.local(os.Stdout, path)
}
if err != nil {
fmt.Println("Error:", err)
}
}
}