forked from ranghetto/go_ocr_space
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
150 lines (125 loc) · 4.51 KB
/
types.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package ocr_space
import (
"net/http"
)
const (
ocrDefaultUrl = "https://api.ocr.space/parse/image"
)
type OCRText struct {
ParsedResults []struct {
TextOverlay struct {
Lines []struct {
Words []struct {
WordText string `json:"WordText"`
Left float64 `json:"Left"`
Top float64 `json:"Top"`
Height float64 `json:"Height"`
Width float64 `json:"Width"`
} `json:"Words"`
MaxHeight float64 `json:"MaxHeight"`
MinTop float64 `json:"MinTop"`
} `json:"Lines"`
HasOverlay bool `json:"HasOverlay"`
Message string `json:"Message"`
} `json:"TextOverlay"`
TextOrientation string `json:"TextOrientation"`
FileParseExitCode int `json:"FileParseExitCode"`
ParsedText string `json:"ParsedText"`
ErrorMessage string `json:"ErrorMessage"`
ErrorDetails string `json:"ErrorDetails"`
} `json:"ParsedResults"`
OCRExitCode int `json:"OCRExitCode"`
IsErroredOnProcessing bool `json:"IsErroredOnProcessing"`
ErrorMessage []string `json:"ErrorMessage"`
ErrorDetails string `json:"ErrorDetails"`
ProcessingTimeInMilliseconds string `json:"ProcessingTimeInMilliseconds"`
SearchablePDFURL string `json:"SearchablePDFURL"`
}
type OCRSpaceAPI struct {
apiKey string
options ApiOptions
}
type ApiOptions struct {
Url string
HTTPClient *http.Client
}
type Lang string
const (
LangArabic Lang = "ara"
LangBulgarian Lang = "bul"
LangChineseSimplified Lang = "chs"
LangChineseTraditional Lang = "cht"
LangCroatian Lang = "hrv"
LangCzech Lang = "cze"
LangDanish Lang = "dan"
LangDutch Lang = "dut"
LangEnglish Lang = "eng"
LangFinnish Lang = "fin"
LangFrench Lang = "fre"
LangGerman Lang = "ger"
LangGreek Lang = "gre"
LangHungarian Lang = "hun"
LangKorean Lang = "kor"
LangItalian Lang = "ita"
LangJapanese Lang = "jpn"
LangPolish Lang = "pol"
LangPortuguese Lang = "por"
LangRussian Lang = "rus"
LangSlovenian Lang = "slv"
LangSpanish Lang = "spa"
LangSwedish Lang = "swe"
LangTurkish Lang = "tur"
)
type Filetype string
const (
FiletypePDF Filetype = "PDF"
FiletypeGIF Filetype = "GIF"
FiletypePNG Filetype = "PNG"
FiletypeJPG Filetype = "JPG"
FiletypeTIF Filetype = "TIF"
FiletypeBMP Filetype = "BMP"
)
type OCREngineVer int
const (
OCREngineV1 OCREngineVer = 1
OCREngineV2 OCREngineVer = 2
)
type Params struct {
// Language used for OCR.
// Default = eng
Language Lang `url:"language,omitempty"`
// If true, returns the coordinates of the bounding boxes for each word.
// If false, the OCR'ed text is returned only as a text block (this makes the JSON reponse smaller).
// Default = False
IsOverlayRequired bool `url:"isOverlayRequired"`
// Overwrites the automatic file type detection based on content-type.
// Supported image file formats are png, jpg (jpeg), gif, tif (tiff) and bmp.
// For document ocr, the api supports the Adobe PDF format. Multi-page TIFF files are supported.
Filetype Filetype `url:"filetype,omitempty"`
// If set to true, the api autorotates the image correctly and sets the TextOrientation parameter in the JSON response.
// If the image is not rotated, then TextOrientation=0, otherwise it is the degree of the rotation, e. g. "270".
// Default = False
DetectOrientation bool `url:"detectOrientation"`
// If true, API generates a searchable PDF.
// This parameter automatically sets isOverlayRequired = true.
// Default = False
IsCreateSearchablePDF bool `url:"isCreateSearchablePdf"`
// If true, the text layer is hidden (not visible)
// Default = False
IsSearchablePDFHideTextLayer bool `url:"isSearchablePdfHideTextLayer"`
// If set to true, the api does some internal upscaling.
// This can improve the OCR result significantly, especially for low-resolution PDF scans.
// Default = False
Scale bool `url:"scale"`
// If set to true, the OCR logic makes sure that the parsed text result is always returned line by line.
// This switch is recommended for table OCR, receipt OCR, invoice processing and all other type of input documents that have a table like structure.
// Default = False
IsTable bool `url:"isTable"`
// OCR engine version: 1 or 2
// Default = 1
OCREngine *OCREngineVer `url:"OCREngine,omitempty"`
}
type File struct {
Name string
Content []byte
}