Skip to content

Commit 0287bc0

Browse files
authored
Example 1: Try it yourself! 📰
Cleaned.
1 parent 3be668e commit 0287bc0

File tree

1 file changed

+35
-81
lines changed

1 file changed

+35
-81
lines changed

OCR_Space Example1.au3

+35-81
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,39 @@
11
#include-once
2-
3-
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
4-
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
5-
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
6-
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
7-
82
#include "OCRSpaceUDF\_OCRSpace_UDF.au3"
93

104

11-
Example1()
12-
; Example2()
13-
14-
Exit
15-
16-
17-
; =========================================================
18-
; _OCRSpace_SetUpOCR( $s_APIKey, _
19-
; $i_OCREngineID = 1, _
20-
; $b_IsTable = False, _
21-
; $b_DetectOrientation = True, _
22-
; $s_LanguageISO = "eng", _
23-
; $b_IsOverlayRequired = False, _
24-
; $b_AutoScaleImage = False, _
25-
; $b_IsSearchablePdfHideTextLayer = False, _
26-
; $b_IsCreateSearchablePdf = False)
27-
; =========================================================
28-
Func Example1()
29-
30-
; THE ONLY MANDATORY PARAMETER!
31-
$s_OCR_APIKEY = ""
32-
33-
$i_OCR_Engine = Default ; Default is Engine 1
34-
35-
; Use a table logic for receipt OCR ?
36-
$b_Table_Logic = False ; Default is False
37-
38-
$b_Detect_Orientation = False ; Default is False
39-
40-
; Create a Searchable PDF ? If true, you'll need to evaluate it.
41-
; You can set a custom evaluation text at the last parameter of _OCRSpace_ImageGetText() [$sURLVar]
42-
; The default evaluation text/string is "__OCRSPACE_SEARCHABLE_PDFLINK"
43-
$b_Create_Searchable_PDF = False
44-
45-
; Should be a valid ISO 639-2 Code, 3 characters. See supported languages @ _OCRSpace_SetUpOCR() function header.
46-
$s_Language = "eng"
47-
48-
; if true, we can do an _ArrayDisplay() or play with the returned array..
49-
$b_Overlay_Info = False
50-
51-
; auto scale the image?
52-
$b_ImageAutoScale = False
53-
54-
; hide the text layer on the searchable PDf? (Default is False).
55-
; At this stage this option is irrelevant since we are not requesting a searchable PDF.
56-
$b_SearchablePdfHideTextLayer = Default
57-
58-
$OCROptions = _OCRSpace_SetUpOCR($s_OCR_APIKEY, $i_OCR_Engine, $b_Table_Logic, $b_Detect_Orientation, $s_Language, $b_Overlay_Info, $b_ImageAutoScale, $b_SearchablePdfHideTextLayer, $b_Create_Searchable_PDF)
59-
60-
; Make the request with return type set to 0 to get a text only.. (1 gets an array instead.)
61-
$Text_Detected = _OCRSpace_ImageGetText($OCROptions, "https://i.imgur.com/eCuYtDe.png", 0, "MyPDFURL")
62-
63-
; Display the result.. Possible data types are a String and 2D array. All depends on integer set at _OCRSpace_ImageGetText() [$iReturnType]
64-
Switch VarGetType($Text_Detected)
65-
66-
Case "array" ; i.e $iReturnType at _OCRSpace_ImageGetText() is set to 1
67-
68-
; Setting $iReturnType to 1 AND $b_Overlay_Info to True returns a 2D array containing the coordinates
69-
; of the bounding boxes for each word detected, in the format : #WordDetected , #Left , #Top , #Height, #Width
70-
_ArrayDisplay($Text_Detected, "@Error : " & @error)
71-
72-
Case Else ; i.e $iReturnType at _OCRSpace_ImageGetText() is set to 0 [DEFAULT]
73-
74-
; For this request, a searchable PDF was not requested in _OCRSpace_SetUpOCR() [$b_Create_Searchable_PDF = false]
75-
; so when evaluating the default evaluation string, the message will be "Searchable PDF not generated as it was not requested."
76-
ConsoleWrite( _
77-
" Detected text : " & $Text_Detected & @CRLF & _
78-
" Error Returned : " & @error & @CRLF & _
79-
" Searchable PDF link : " & Eval((IsDeclared("MyPDFURL") = $DECLARED_GLOBAL) ? "MyPDFURL" : "__OCRSPACE_SEARCHABLE_PDFLINK") & @CRLF)
80-
EndSwitch
81-
82-
Return
83-
EndFunc ;==>Example1
84-
85-
5+
; The only mandatory parameter!
6+
Global Const $OCRSPACEAPIKEY = ""
7+
8+
$i_OCR_Engine = Default ; Default = 1
9+
$b_Table_Logic = False ; Default = False
10+
$b_Detect_Orientation = False ; Default = False
11+
$s_Language = "eng" ; Valid Lang ISO 639-2 Code. Default = "eng"
12+
$b_Overlay_Info = False ; Return array ? Default = False
13+
$b_ImageAutoScale = False ; Auto scale the image ? Default = False
14+
15+
$b_Create_Searchable_PDF = False ; Default = False
16+
$b_SearchablePdfHideTextLayer = Default ; PDF Options only make sense if a Searchable PDF was requested at $b_Create_Searchable_PDF
17+
18+
19+
$a_lOCROptions = _OCRSpace_SetUpOCR( _
20+
$OCRSPACEAPIKEY, _
21+
$i_OCR_Engine, _
22+
$b_Table_Logic, _
23+
$b_Detect_Orientation, _
24+
$s_Language, _
25+
$b_Overlay_Info, _
26+
$b_ImageAutoScale, _
27+
$b_SearchablePdfHideTextLayer, _
28+
$b_Create_Searchable_PDF)
29+
30+
; Scan an Image from Imgur: https://i.imgur.com/eCuYtDe.png
31+
$s_lText_Detected = _OCRSpace_ImageGetText($a_lOCROptions, "https://i.imgur.com/eCuYtDe.png", 0, "MyPDFURL")
32+
33+
; A searchable PDF was not requested above [$b_Create_Searchable_PDF = false] so a PDF link
34+
; will result : "Searchable PDF not generated as it was not requested."
35+
ConsoleWrite( _
36+
" Detected text : " & $s_lText_Detected & @CRLF & _
37+
" Error Returned : " & @error & @CRLF & _
38+
" Searchable PDF link : " & Eval("MyPDFURL") & @CRLF)
39+
Exit

0 commit comments

Comments
 (0)