-
Notifications
You must be signed in to change notification settings - Fork 71
/
delphi ocr api.pas
38 lines (32 loc) · 1.11 KB
/
delphi ocr api.pas
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
uses
IdHTTP, idMultipartFormData, json;
procedure TfrmMain.btnOCRStartClick(Sender: TObject);
var
IdHTTP1: TIdHTTP;
MPData: TIdMultiPartFormDataStream;
JsonObject: TJSONObject;
JSonValue: TJSONValue;
sResponse: string;
sValue: string;
begin
try
IdHTTP1 := TIdHTTP.Create(nil);
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
MPData := TIdMultiPartFormDataStream.Create;
MPData.AddFile('file', 'C:\Pictures\Picture.jpg', 'image/jpg');
MPData.AddFormField('apikey', '012345678901234');
MPData.AddFormField('language', 'eng');
MPData.AddFormField('isOverlayRequired', 'False');
sResponse := IdHTTP1.Post('https://api.ocr.space/parse/image', MPData);
JsonObject := TJSONObject.Create;
JsonValue := JsonObject.ParseJSONValue(sResponse);
JsonValue:=(JsonValue as TJSONObject).Get('ParsedResults').JSONValue;
if (JsonValue is TJSONArray) then
sValue := ((JsonValue as TJSONArray).Items[0] as TJSonObject).Get('ParsedText').JSONValue.Value;
Memo1.Lines.Add(sValue);
finally
IdHTTP1.Free;
MPData.Free;
JsonObject.Free;
end;
end;