22
22
PSimpleOCR = ^TSimpleOCR;
23
23
PFontSet = ^TFontSet;
24
24
POCRFilter = ^TOCRFilter;
25
+ POCRTarget = ^TOCRTarget;
25
26
26
27
procedure _LapeFontSet_Create (const Params: PParamArray; const Result: Pointer); cdecl;
27
28
begin
@@ -38,24 +39,24 @@ procedure _LapeFontSet_TextToTPA(const Params: PParamArray; const Result: Pointe
38
39
PPointArray(Result)^ := PFontSet(Params^[0 ])^.TextToTPA(PString(Params^[1 ])^);
39
40
end ;
40
41
41
- procedure _LapeSimpleOCR_LocateText (const Params: PParamArray; const Result: Pointer); cdecl;
42
+ procedure _LapeSimpleOCR_Locate (const Params: PParamArray; const Result: Pointer); cdecl;
42
43
begin
43
- PSingle(Result)^ := PSimpleOCR(Params^[0 ])^.LocateText(PString (Params^[1 ])^, PFontSet (Params^[2 ])^, POCRFilter (Params^[3 ])^);
44
+ PSingle(Result)^ := PSimpleOCR(Params^[0 ])^.Locate(POCRTarget (Params^[1 ])^, PString (Params^[2 ])^, PFontSet (Params^[3 ])^, POCRFilter(Params^[ 4 ])^);
44
45
end ;
45
46
46
47
procedure _LapeSimpleOCR_Recognize (const Params: PParamArray; const Result: Pointer); cdecl;
47
48
begin
48
- PString(Result)^ := PSimpleOCR(Params^[0 ])^.Recognize(POCRFilter (Params^[1 ])^, PFontSet (Params^[2 ])^);
49
+ PString(Result)^ := PSimpleOCR(Params^[0 ])^.Recognize(POCRTarget (Params^[1 ])^, POCRFilter (Params^[2 ])^, PFontSet(Params^[ 3 ])^);
49
50
end ;
50
51
51
52
procedure _LapeSimpleOCR_RecognizeStatic (const Params: PParamArray; const Result: Pointer); cdecl;
52
53
begin
53
- PString(Result)^ := PSimpleOCR(Params^[0 ])^.RecognizeStatic(POCRFilter (Params^[1 ])^, PFontSet (Params^[2 ])^);
54
+ PString(Result)^ := PSimpleOCR(Params^[0 ])^.RecognizeStatic(POCRTarget (Params^[1 ])^, POCRFilter (Params^[2 ])^, PFontSet(Params^[ 3 ])^);
54
55
end ;
55
56
56
57
procedure _LapeSimpleOCR_RecognizeLines (const Params: PParamArray; const Result: Pointer); cdecl;
57
58
begin
58
- PStringArray(Result)^ := PSimpleOCR(Params^[0 ])^.RecognizeLines(POCRFilter (Params^[1 ])^, PFontSet (Params^[2 ])^);
59
+ PStringArray(Result)^ := PSimpleOCR(Params^[0 ])^.RecognizeLines(POCRTarget (Params^[1 ])^, POCRFilter (Params^[2 ])^, PFontSet(Params^[ 3 ])^);
59
60
end ;
60
61
61
62
initialization
@@ -92,10 +93,8 @@ initialization
92
93
' end; ' + LineEnding +
93
94
' ' + LineEnding +
94
95
' ColorFilter: record ' + LineEnding +
95
- ' Colors: array of record ' + LineEnding +
96
- ' Color: Integer; ' + LineEnding +
97
- ' Tolerance: Single; ' + LineEnding +
98
- ' end; ' + LineEnding +
96
+ ' Colors: TIntegerArray; ' + LineEnding +
97
+ ' Tolerances: TSingleArray; ' + LineEnding +
99
98
' Invert: Boolean; ' + LineEnding +
100
99
' end; ' + LineEnding +
101
100
' ' + LineEnding +
@@ -121,6 +120,8 @@ initialization
121
120
' end;' ,
122
121
' TOCRMatch' );
123
122
123
+ addGlobalType(' TIntegerMatrix' , ' TOCRTarget' );
124
+
124
125
addGlobalType(
125
126
' packed record ' + LineEnding +
126
127
' Client: TIntegerMatrix; ' + LineEnding +
@@ -132,15 +133,15 @@ initialization
132
133
' end;' ,
133
134
' TSimpleOCR' );
134
135
135
- addGlobalFunc(' function TFontSet.Create(FileName : String; SpaceWidth: Integer = 4): TFontSet; static; native;' , @_LapeFontSet_Create);
136
+ addGlobalFunc(' function TFontSet.Create(Directory : String; SpaceWidth: Integer = 4): TFontSet; static; native;' , @_LapeFontSet_Create);
136
137
addGlobalFunc(' function TFontSet.TextToMatrix(Text: String): TIntegerMatrix; native;' , @_LapeFontSet_TextToMatrix);
137
138
addGlobalFunc(' function TFontSet.TextToTPA(Text: String): TPointArray; native;' , @_LapeFontSet_TextToTPA);
138
139
139
- addGlobalFunc(' function TSimpleOCR.Recognize(Filter: TOCRFilter; Font: TFontSet): String; native;' , @_LapeSimpleOCR_Recognize);
140
- addGlobalFunc(' function TSimpleOCR.RecognizeLines(Filter: TOCRFilter; Font: TFontSet): TStringArray; native;' , @_LapeSimpleOCR_RecognizeLines);
141
- addGlobalFunc(' function TSimpleOCR.RecognizeStatic(Filter: TOCRFilter; Font: TFontSet): String; native;' , @_LapeSimpleOCR_RecognizeStatic);
140
+ addGlobalFunc(' function TSimpleOCR.Recognize(Target: TOCRTarget; Filter: TOCRFilter; Font: TFontSet): String; native;' , @_LapeSimpleOCR_Recognize);
141
+ addGlobalFunc(' function TSimpleOCR.RecognizeLines(Target: TOCRTarget; Filter: TOCRFilter; Font: TFontSet): TStringArray; native;' , @_LapeSimpleOCR_RecognizeLines);
142
+ addGlobalFunc(' function TSimpleOCR.RecognizeStatic(Target: TOCRTarget; Filter: TOCRFilter; Font: TFontSet): String; native;' , @_LapeSimpleOCR_RecognizeStatic);
142
143
143
- addGlobalFunc(' function TSimpleOCR.LocateText( Text: String; Font: TFontSet; Filter: TOCRFilter): Single; native;' , @_LapeSimpleOCR_LocateText );
144
+ addGlobalFunc(' function TSimpleOCR.Locate(Target: TOCRTarget; Text: String; Font: TFontSet; Filter: TOCRFilter): Single; native;' , @_LapeSimpleOCR_Locate );
144
145
145
146
addCode([
146
147
' {$IFDEF SIMPLEOCR_CHECK_SIZES}' ,
@@ -183,24 +184,15 @@ initialization
183
184
' raise "TOCRColorFilter.Create: Length(Colors) <> Length(Tolerances)";' ,
184
185
' ' ,
185
186
' Result.FilterType := 1;' ,
186
- ' ' ,
187
- ' SetLength(Result.ColorFilter.Colors, Length(Colors));' ,
188
- ' for I := 0 to High(Colors) do' ,
189
- ' begin' ,
190
- ' Result.ColorFilter.Colors[I].Color := Colors[I];' ,
191
- ' Result.ColorFilter.Colors[I].Tolerance := Tolerances[I];' ,
192
- ' end;' ,
187
+ ' Result.ColorFilter.Colors := TIntegerArray(Colors);' ,
188
+ ' Result.ColorFilter.Tolerances := Tolerances;' ,
193
189
' end;' ,
194
190
' ' ,
195
191
' function TOCRColorFilter.Create(Colors: TColorArray): TOCRColorFilter; static; overload;' ,
196
- ' var' ,
197
- ' I: Integer;' ,
198
192
' begin' ,
199
193
' Result.FilterType := 1;' ,
200
- ' ' ,
201
- ' SetLength(Result.ColorFilter.Colors, Length(Colors));' ,
202
- ' for I := 0 to High(Colors) do' ,
203
- ' Result.ColorFilter.Colors[I].Color := Colors[I];' ,
194
+ ' Result.ColorFilter.Colors := TIntegerArray(Colors);' ,
195
+ ' SetLength(Result.ColorFilter.Tolerances, Length(Colors));' ,
204
196
' end;' ,
205
197
' ' ,
206
198
' function TOCRInvertColorFilter.Create(Colors: TColorArray; Tolerances: TSingleArray): TOCRInvertColorFilter; static; overload;' ,
@@ -212,13 +204,8 @@ initialization
212
204
' ' ,
213
205
' Result.FilterType := 4;' ,
214
206
' Result.ColorFilter.Invert := True;' ,
215
- ' ' ,
216
- ' SetLength(Result.ColorFilter.Colors, Length(Colors));' ,
217
- ' for I := 0 to High(Colors) do' ,
218
- ' begin' ,
219
- ' Result.ColorFilter.Colors[I].Color := Colors[I];' ,
220
- ' Result.ColorFilter.Colors[I].Tolerance := Tolerances[I];' ,
221
- ' end;' ,
207
+ ' Result.ColorFilter.Colors := TIntegerArray(Colors);' ,
208
+ ' Result.ColorFilter.Tolerances := Tolerances;' ,
222
209
' end;' ,
223
210
' ' ,
224
211
' function TOCRInvertColorFilter.Create(Colors: TColorArray): TOCRInvertColorFilter; static; overload;' ,
@@ -227,17 +214,15 @@ initialization
227
214
' begin' ,
228
215
' Result.FilterType := 4;' ,
229
216
' Result.ColorFilter.Invert := True;' ,
230
- ' ' ,
231
- ' SetLength(Result.ColorFilter.Colors, Length(Colors));' ,
232
- ' for I := 0 to High(Colors) do' ,
233
- ' Result.ColorFilter.Colors[I].Color := Colors[I];' ,
217
+ ' Result.ColorFilter.Colors := TIntegerArray(Colors);' ,
218
+ ' SetLength(Result.ColorFilter.Tolerances, Length(Colors));' ,
234
219
' end;' ,
235
220
' ' ,
236
- ' function TOCRThresholdFilter.Create(Amount: Integer; Invert: Boolean = False ): TOCRThresholdFilter; static;' ,
221
+ ' function TOCRThresholdFilter.Create(Invert: Boolean = False; C: Integer = 0 ): TOCRThresholdFilter; static;' ,
237
222
' begin' ,
238
223
' Result.FilterType := 2;' ,
239
- ' Result.ThresholdFilter.Amount := Amount;' ,
240
224
' Result.ThresholdFilter.Invert := Invert;' ,
225
+ ' Result.ThresholdFilter.C := C;' ,
241
226
' end;' ,
242
227
' ' ,
243
228
' function TOCRShadowFilter.Create(MaxShadowValue: Integer = 25; Tolerance: Single = 5): TOCRShadowFilter; static;' ,
@@ -249,28 +234,23 @@ initialization
249
234
' ' ,
250
235
' function TSimpleOCR.Recognize(Area: TBox; Filter: TOCRFilter; constref Font: TFontSet): String; overload;' ,
251
236
' begin' ,
252
- ' Self.Client := TSimpleOCR._GetColorsMatrix(Area);' ,
253
237
' Self.Offset := [Area.X1, Area.Y1];' ,
254
238
' ' ,
255
- ' Result := Self.Recognize(Filter, Font);' ,
239
+ ' Result := Self.Recognize(TSimpleOCR._GetColorsMatrix(Area), Filter, Font);' ,
256
240
' end;' ,
257
241
' ' ,
258
242
' function TSimpleOCR.RecognizeStatic(Area: TBox; Filter: TOCRFilter; constref Font: TFontSet): String; overload;' ,
259
243
' begin' ,
260
- ' Self.Client := TSimpleOCR._GetColorsMatrix(Area);' ,
261
244
' Self.Offset := [Area.X1, Area.Y1];' ,
262
245
' ' ,
263
- ' Result := Self.RecognizeStatic(Filter, Font);' ,
246
+ ' Result := Self.RecognizeStatic(TSimpleOCR._GetColorsMatrix(Area), Filter, Font);' ,
264
247
' end;' ,
265
248
' ' ,
266
249
' function TSimpleOCR.RecognizeLines(Area: TBox; Filter: TOCRFilter; constref Font: TFontSet): TStringArray; overload;' ,
267
- ' var' ,
268
- ' I: Integer;' ,
269
250
' begin' ,
270
- ' Self.Client := TSimpleOCR._GetColorsMatrix(Area);' ,
271
251
' Self.Offset := [Area.X1, Area.Y1];' ,
272
252
' ' ,
273
- ' Result := Self.RecognizeLines(Filter, Font);' ,
253
+ ' Result := Self.RecognizeLines(TSimpleOCR._GetColorsMatrix(Area), Filter, Font);' ,
274
254
' end;' ,
275
255
' ' ,
276
256
' function TSimpleOCR.RecognizeNumber(Area: TBox; Filter: TOCRFilter; constref Font: TFontSet): Int64;' ,
@@ -288,12 +268,11 @@ initialization
288
268
' Result := StrToInt64(Text);' ,
289
269
' end;' ,
290
270
' ' ,
291
- ' function TSimpleOCR.LocateText (Area: TBox; Text: String; constref Font: TFontSet; Filter: TOCRFilter): Single; overload;' ,
271
+ ' function TSimpleOCR.Locate (Area: TBox; Text: String; constref Font: TFontSet; Filter: TOCRFilter): Single; overload;' ,
292
272
' begin' ,
293
- ' Self.Client := TSimpleOCR._GetColorsMatrix(Area);' ,
294
273
' Self.Offset := [Area.X1, Area.Y1];' ,
295
274
' ' ,
296
- ' Result := Self.LocateText( Text, Font, Filter);' ,
275
+ ' Result := Self.Locate(TSimpleOCR._GetColorsMatrix(Area), Text, Font, Filter);' ,
297
276
' end;'
298
277
]);
299
278
0 commit comments