-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimage.go
75 lines (61 loc) · 2.13 KB
/
image.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
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"io/ioutil"
//rcn "recognition"
"time"
rcn "github.com/tuputech/tupu-go-sdk/recognition"
)
func main() {
secretID := "Your SecretID"
handler, e := rcn.NewHandler("rsa_private_key.pem")
if e != nil {
fmt.Printf("Failed: %v\n", e)
return
}
//Optional Step: using http-client created by your own
// tr := &http.Transport{
// MaxIdleConns: 10,
// IdleConnTimeout: 30 * time.Second,
// DisableCompression: true,
// }
// handler.Client = &http.Client{Transport: tr}
images1 := []string{"your image url"}
// just for images
printResult(handler.PerformWithURL(secretID, images1))
// Number of tags less than number of images, the rest images will use the last tag
tags := []string{"image tag"}
printResult(handler.PerformWithURL(secretID, images1, handler.WithTags(tags)))
// run by appoint task
tasks := []string{"54bcfc6c329af61034f7c2fc"}
printResult(handler.PerformWithURL(secretID, images1, handler.WithTasks(tasks)))
// with tag and run by appoint task
printResult(handler.PerformWithURL(secretID, images1, handler.WithTasks(tasks), handler.WithTags(tags)))
// Using local file path
filepaths := []string{"your filepath"}
printResult(handler.PerformWithPath(secretID, filepaths, handler.WithTags(tags)))
// Using local file or binary data
fileBytes, e2 := ioutil.ReadFile("your speech filePath")
if e2 != nil {
fmt.Printf("Could not load image: %v", e2)
return
}
imgBinary := rcn.NewBinaryImage(fileBytes, "1.jpg")
defer imgBinary.ClearBuffer()
images2 := []*rcn.Image{rcn.NewLocalImage("your speech filePath"), imgBinary}
printResult(handler.Perform(secretID, images2, []string{"Local Image", "Using Buffer"}, nil))
}
func printResult(result string, statusCode int, e error) {
if e != nil {
fmt.Printf("Failed: %v\n", e)
return
}
fmt.Println("-------- v1.6 --------")
fmt.Printf("Status-Code: %v\n-----\n", statusCode)
r := rcn.ParseResult(result)
fmt.Printf("- Code: %v %v\n- Time: %v\n", r.Code, r.Message, time.Unix(int64(float64(r.Timestamp)/1000), 0))
for k, v := range r.Tasks {
fmt.Printf("- Task: [%v]\n%v\n", k, v)
}
fmt.Println("----------------------")
}