Skip to content

Commit 9c33d59

Browse files
committed
Added GO SDK
1 parent 2872068 commit 9c33d59

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

ocr/getting-started/available-sdks/_index.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
weight: 50
3-
date: "2022-07-13"
3+
date: "2023-07-20"
44
author: "Vladimir Lapin"
55
type: docs
66
url: /available-sdks/
@@ -30,6 +30,8 @@ SDKs handle all the routine operations such as establishing connections, sending
3030
Add OCR functionality to AWS Lambda, Azure Functions, services, and applications written in Node.js by querying our REST API.
3131
- [Aspose.OCR Cloud for Android](https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-android)
3232
Turn a smartphone into a full featured OCR scanner. Aspose.OCR service runs in the cloud and supports even entry-level and legacy smartphones.
33+
- [Aspose.OCR Cloud for Go](https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-go)
34+
Allow your Go applications to extract text from images, read street photos, and many more.
3335

3436
All SDKs are open-source distributed under [MIT License](https://opensource.org/licenses/MIT). You can freely use them for any projects, including commercial and proprietary applications, as well as modify any part of the code.
3537

@@ -39,7 +41,7 @@ The provided code is fully tested and ready to run out of the box.
3941

4042
See the examples below for a quick overview of how SDKs can make your development easier.
4143

42-
{{< tabs tabTotal="4" tabID="4" tabName1="C#" tabName2="Java" tabName3="Python" tabName4="Android" >}}
44+
{{< tabs tabTotal="5" tabID="4" tabName1="C#" tabName2="Java" tabName3="Python" tabName4="Android" tabName5="Go" >}}
4345

4446
{{< tab tabNum="1" >}}
4547

@@ -65,5 +67,98 @@ See the examples below for a quick overview of how SDKs can make your developmen
6567

6668
{{< /tab >}}
6769

70+
{{< tab tabNum="5" >}}
71+
72+
```go
73+
package main
74+
75+
import (
76+
"context"
77+
"encoding/base64"
78+
"fmt"
79+
"io/ioutil"
80+
81+
asposeocrcloud "github.com/aspose-ocr-cloud/aspose-ocr-cloud-go"
82+
)
83+
84+
func main() {
85+
86+
clientId := "YOUR_CLIENT_ID"
87+
clientSecret := "YOUR_CLIENT_SECRET"
88+
configuration := asposeocrcloud.NewConfiguration(clientId, clientSecret)
89+
apiClient := asposeocrcloud.NewAPIClient(configuration)
90+
91+
filePath := "../samples/latin.png" // Path to your file
92+
93+
// Read your file data and convert it into base64 string
94+
fileBytes, err := ioutil.ReadFile(filePath)
95+
if err != nil || fileBytes == nil {
96+
fmt.Println("Read file error:", err)
97+
return
98+
}
99+
fileb64Encoded := base64.StdEncoding.EncodeToString(fileBytes)
100+
101+
// Step 1: create request body and sent it to OCR Cloud to receive task ID
102+
recognitionSettings := *asposeocrcloud.NewOCRSettingsRecognizeImage()
103+
recognitionSettings.Language = asposeocrcloud.LANGUAGE_ENGLISH.Ptr()
104+
recognitionSettings.DsrMode = asposeocrcloud.DSRMODE_NO_DSR_NO_FILTER.Ptr()
105+
recognitionSettings.DsrConfidence = asposeocrcloud.DSRCONFIDENCE_DEFAULT.Ptr()
106+
*recognitionSettings.MakeBinarization = false
107+
*recognitionSettings.MakeSkewCorrect = false
108+
*recognitionSettings.MakeUpsampling = false
109+
*recognitionSettings.MakeSpellCheck = false
110+
*recognitionSettings.MakeContrastCorrection = false
111+
recognitionSettings.ResultType = asposeocrcloud.RESULTTYPE_TEXT.Ptr()
112+
recognitionSettings.ResultTypeTable = asposeocrcloud.RESULTTYPETABLE_TEXT.Ptr()
113+
114+
requestBody := *asposeocrcloud.NewOCRRecognizeImageBody(
115+
fileb64Encoded,
116+
recognitionSettings,
117+
)
118+
119+
taskId, httpRes, err := apiClient.RecognizeImageApi.PostRecognizeImage(context.Background()).OCRRecognizeImageBody(requestBody).Execute()
120+
if err != nil || httpRes.StatusCode != 200 {
121+
fmt.Println("API error:", err)
122+
return
123+
}
124+
125+
fmt.Printf("File successfully sent. Your TaskID is %s \n", taskId)
126+
127+
// Step 2: request task results using task ID
128+
ocrResp, httpRes, err := apiClient.RecognizeImageApi.GetRecognizeImage(context.Background()).Id(taskId).Execute()
129+
if err != nil || httpRes.StatusCode != 200 || ocrResp == nil {
130+
fmt.Println("API error:", err)
131+
return
132+
}
133+
134+
if *ocrResp.TaskStatus == asposeocrcloud.OCRTASKSTATUS_COMPLETED {
135+
if !ocrResp.Results[0].Data.IsSet() {
136+
fmt.Println("Response is empty")
137+
return
138+
}
139+
140+
// Decode results and write to file
141+
decodedBytes, err := base64.StdEncoding.DecodeString(*ocrResp.Results[0].Data.Get())
142+
if err != nil {
143+
fmt.Println("Decode error:", err)
144+
return
145+
}
146+
147+
resultFilePath := "../results/" + taskId + ".txt"
148+
err = ioutil.WriteFile(resultFilePath, decodedBytes, 0644)
149+
if err != nil {
150+
fmt.Println("Write file error:", err)
151+
return
152+
}
153+
154+
fmt.Printf("Task result successfully saved at %s \n", resultFilePath)
155+
} else {
156+
fmt.Printf("Sorry, task %s is not completed yet. You can request results later. Task status: %s\n", taskId, *ocrResp.TaskStatus)
157+
}
158+
}
159+
```
160+
161+
{{< /tab >}}
162+
68163
{{< /tabs >}}
69164

ocr/product-overview/supported-patterns/_index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
weight: 40
3-
date: "2022-01-31"
3+
date: "2023-07-20"
44
author: "Vladimir Lapin"
55
type: docs
66
url: /supported-patterns/
@@ -16,8 +16,10 @@ Aspose.OCR Cloud provides several predefined patterns to maximize recognition ac
1616

1717
- Read an entire image.
1818
- Read a scanned PDF document and add text as a searchable overlay.
19+
- Read all texts from a photo, including street photos.
1920
- Extract text from a specific region of the image.
2021
- Convert an image containing tabular data into a spreadsheet or CSV file.
2122
- Extract data from a scanned or photographed receipt.
2223
- Improve image resolution, correct rotated, skewed and distorted images, automatically remove image defects.
2324
- Read aloud text on an image.
25+
- Identify fonts and styles on an image.

0 commit comments

Comments
 (0)