-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (51 loc) · 1.25 KB
/
main.go
File metadata and controls
57 lines (51 loc) · 1.25 KB
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
package main
import (
"fmt"
"io/ioutil"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/textract"
)
func CreateSession() *session.Session {
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Profile: *aws.String("my"),
Config: aws.Config{
Region: aws.String("ap-southeast-1"), // London
},
}))
return sess
}
var textractSession *textract.Textract
func init() {
textractSession = textract.New(CreateSession())
}
func main() {
file, err := ioutil.ReadFile("front.jpg")
if err != nil {
panic(err)
}
textractSession.DetectDocumentTextRequest(&textract.DetectDocumentTextInput{
// Document: ,
})
resp, err := textractSession.DetectDocumentText(&textract.DetectDocumentTextInput{
Document: &textract.Document{
Bytes: file,
},
})
if err != nil {
panic(err)
}
for i := 1; i < len(resp.Blocks); i++ {
a := *resp.Blocks[i]
fmt.Println(a)
if *resp.Blocks[i].BlockType == "LINE" {
fmt.Println(*resp.Blocks[i].Text)
} else if *resp.Blocks[i].BlockType == "WORD" {
fmt.Println(*resp.Blocks[i].Text)
} else {
fmt.Println(*resp.Blocks[i].BlockType)
fmt.Println(*resp.Blocks[i].Text)
}
}
}