-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext.go
222 lines (175 loc) · 7.72 KB
/
text.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// 文字识别
package gdm
import (
"fmt"
ole "github.com/go-ole/go-ole"
"github.com/rogeecn/draw"
"github.com/rogeecn/gdm/color"
"github.com/rogeecn/gdm/utils"
"strings"
)
// AddDict 给指定的字库中添加一条字库信息
func (com *DmSoft) AddDict(index int, dictInfo string) bool {
ret, _ := com.dm.CallMethod("AddDict", index, dictInfo)
return utils.IsOK(ret.Val)
}
// ClearDict 清空指定的字库
func (com *DmSoft) ClearDict(index int) bool {
ret, _ := com.dm.CallMethod("ClearDict", index)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) EnableShareDict(enable int) bool {
ret, _ := com.dm.CallMethod("EnableShareDict", enable)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) FetchWord(r *draw.Rect, color *color.Colors, word string) string {
ret, _ := com.dm.CallMethod("FetchWord", r.Left(), r.Top(), r.Right(), r.Bottom(), color.String(), word)
return ret.ToString()
}
func (com *DmSoft) FindStr(r *draw.Rect, str []string, colors *color.Colors, sim float32) (*draw.Point, bool) {
x := ole.NewVariant(ole.VT_I4, 0)
y := ole.NewVariant(ole.VT_I4, 0)
ret, _ := com.dm.CallMethod("FindStr", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim, &x, &y)
ptX := int(x.Val)
ptY := int(y.Val)
x.Clear()
y.Clear()
return draw.NewPoint(ptX, ptY), utils.IsFindStrOK(ret.Val)
}
func (com *DmSoft) FindStrE(r *draw.Rect, str []string, colors *color.Colors, sim float32) *utils.FindItemResult {
ret, _ := com.dm.CallMethod("FindStrE", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim)
// log.Debugf("FindStrE result: %s", ret.ToString())
return utils.NewFindItemResult(str, ret.ToString())
}
func (com *DmSoft) FindStrEx(r *draw.Rect, str []string, colors *color.Colors, sim float32) *utils.FindItemsResult {
ret, _ := com.dm.CallMethod("FindStrEx", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim)
return utils.NewFindItemsResult(str, ret.ToString())
}
func (com *DmSoft) FindStrFast(r *draw.Rect, str []string, colors *color.Colors, sim float32, intX *int, intY *int) *utils.FindItemResult {
x := ole.NewVariant(ole.VT_I4, 0)
y := ole.NewVariant(ole.VT_I4, 0)
ret, _ := com.dm.CallMethod("FindStrFast", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim, &x, &y)
ptX := int(x.Val)
ptY := int(y.Val)
x.Clear()
y.Clear()
return utils.NewFindItemResult(str, fmt.Sprintf("%s|%d|%d", ret.ToString(), ptX, ptY))
}
func (com *DmSoft) FindStrFastE(r *draw.Rect, str []string, colors *color.Colors, sim float32) *utils.FindItemResult {
ret, _ := com.dm.CallMethod("FindStrFastE", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim)
return utils.NewFindItemResult(str, ret.ToString())
}
func (com *DmSoft) FindStrFastEx(r *draw.Rect, str []string, colors *color.Colors, sim float32) *utils.FindItemsResult {
ret, _ := com.dm.CallMethod("FindStrFastEx", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim)
return utils.NewFindItemsResult(str, ret.ToString())
}
func (com *DmSoft) FindStrWithFont(r *draw.Rect, str []string, colors *color.Colors, sim float32, fontName string, fontSize, flag int) *utils.FindItemResult {
x := ole.NewVariant(ole.VT_I4, 0)
y := ole.NewVariant(ole.VT_I4, 0)
ret, _ := com.dm.CallMethod("FindStrWithFont", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim, fontName, fontSize, flag, &x, &y)
ptX := int(x.Val)
ptY := int(y.Val)
x.Clear()
y.Clear()
return utils.NewFindItemResult(str, fmt.Sprintf("%s|%d|%d", ret.ToString(), ptX, ptY))
}
func (com *DmSoft) FindStrWithFontE(r *draw.Rect, str []string, colors *color.Colors, sim float32, fontName string, fontSize, flag int) *utils.FindItemResult {
ret, _ := com.dm.CallMethod("FindStrWithFontE", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim, fontName, fontSize, flag)
return utils.NewFindItemResult(str, ret.ToString())
}
func (com *DmSoft) FindStrWithFontEx(r *draw.Rect, str []string, colors *color.Colors, sim float32, fontName string, fontSize, flag int) *utils.FindItemsResult {
ret, _ := com.dm.CallMethod("FindStrWithFontEx", r.Left(), r.Top(), r.Right(), r.Bottom(), strings.Join(str, "|"), colors.String(), sim, fontName, fontSize, flag)
return utils.NewFindItemsResult(str, ret.ToString())
}
func (com *DmSoft) GetDict(index, fontIndex int) string {
ret, _ := com.dm.CallMethod("GetDict", index, fontIndex)
return ret.ToString()
}
func (com *DmSoft) GetDictCount(index int) int {
ret, _ := com.dm.CallMethod("GetDictCount", index)
return int(ret.Val)
}
func (com *DmSoft) GetDictInfo(str, fontName string, fontSize, flag int) string {
ret, _ := com.dm.CallMethod("GetDictInfo", str, fontName, fontSize, flag)
return ret.ToString()
}
func (com *DmSoft) GetNowDict() int {
ret, _ := com.dm.CallMethod("GetNowDict")
return int(ret.Val)
}
func (com *DmSoft) GetWordResultCount(str string) int {
ret, _ := com.dm.CallMethod("GetWordResultCount", str)
return int(ret.Val)
}
func (com *DmSoft) Ocr(r *draw.Rect, colors *color.Colors, sim float32) string {
ret, _ := com.dm.CallMethod("Ocr", r.Left(), r.Top(), r.Right(), r.Bottom(), colors.String(), sim)
return ret.ToString()
}
func (com *DmSoft) OcrEx(r *draw.Rect, colors *color.Colors, sim float32) *utils.OcrResuts {
ret, _ := com.dm.CallMethod("OcrEx", r.Left(), r.Top(), r.Right(), r.Bottom(), colors.String(), sim)
return utils.NewOcrResuts(ret.ToString())
}
func (com *DmSoft) OcrInFile(r *draw.Rect, picName, colors *color.Colors, sim float32) string {
ret, _ := com.dm.CallMethod("OcrInFile", r.Left(), r.Top(), r.Right(), r.Bottom(), picName, colors.String(), sim)
return ret.ToString()
}
func (com *DmSoft) SaveDict(index int, file string) bool {
ret, _ := com.dm.CallMethod("SaveDict", index, file)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetColGapNoDict(colGap int) bool {
ret, _ := com.dm.CallMethod("SetColGapNoDict", colGap)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetDefaultDict(dict string) {
com.SetDict(0, dict)
com.UseDict(0)
}
func (com *DmSoft) SetDict(index int, file string) bool {
ret, _ := com.dm.CallMethod("SetDict", index, file)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetDictMem(index, addr, size int) bool {
ret, _ := com.dm.CallMethod("SetDictMem", index, addr, size)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetDictPwd(pwd string) bool {
ret, _ := com.dm.CallMethod("SetDictPwd", pwd)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetExactOcr(exactOcr int) bool {
ret, _ := com.dm.CallMethod("SetExactOcr", exactOcr)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetMinColGap(minColGap int) bool {
ret, _ := com.dm.CallMethod("SetMinColGap", minColGap)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetMinRowGap(minRowGap int) bool {
ret, _ := com.dm.CallMethod("SetMinRowGap", minRowGap)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetRowGapNoDict(RowGap int) bool {
ret, _ := com.dm.CallMethod("SetRowGapNoDict", RowGap)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetWordGap(wordGap int) bool {
ret, _ := com.dm.CallMethod("SetWordGap", wordGap)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetWordGapNoDict(wordGap int) bool {
ret, _ := com.dm.CallMethod("SetWordGapNoDict", wordGap)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetWordLineHeight(lineHeight int) bool {
ret, _ := com.dm.CallMethod("SetWordLineHeight", lineHeight)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) SetWordLineHeightNoDict(lineHeight int) bool {
ret, _ := com.dm.CallMethod("SetWordLineHeightNoDict", lineHeight)
return utils.IsOK(ret.Val)
}
func (com *DmSoft) UseDict(index int) bool {
ret, _ := com.dm.CallMethod("UseDict", index)
return utils.IsOK(ret.Val)
}