Skip to content

Commit d7d57b4

Browse files
committed
Add LocateText
Add DrawText Add TCompareRules.UseShadowForColor Clean up source
1 parent 5b4b923 commit d7d57b4

8 files changed

+692
-301
lines changed

.github/workflows/autobuild.yml

+61-67
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,111 @@
1-
# FPC & Lazarus is built on each platform (takes ~15mins) then stored in cache.
2-
# Cache is removed if not used in 7 days and is restricted to 5gb. Each lazarus install is ~500mb.
1+
# FPC & Lazarus is built on each platform (takes ~10mins) then stored in cache.
2+
# Cache is removed if not used in 7 days and is restricted to 5gb. Each lazarus install is ~300mb.
33

4-
name: autobuild
4+
name: Build
55

66
on: [push, pull_request]
77

88
jobs:
99
build:
1010
name: ${{ matrix.config.name }}
1111
runs-on: ${{ matrix.config.os }}
12-
env:
13-
OS: ${{ matrix.config.os }}
14-
NAME: ${{ matrix.config.name }}
15-
LAZ_VER: ${{ matrix.config.LAZ_VER }}
16-
FPC_VER: ${{ matrix.config.FPC_VER }}
17-
LAZ_OPT: ${{ matrix.config.LAZ_OPT }}
18-
ARTIFACT: ${{ matrix.config.ARTIFACT }}
19-
FPCUP: ${{ matrix.config.FPCUP }}
20-
FPCUP_OPT: ${{ matrix.config.FPCUP_OPT }}
12+
defaults:
13+
run:
14+
shell: bash
2115
strategy:
2216
fail-fast: false
2317
matrix:
2418
config:
2519
- os: windows-latest
2620
name: 'Windows 32'
27-
FPCUP: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.0b/fpclazup-i386-win32.exe'
28-
FPC_VER: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
29-
LAZ_VER: 'trunk'
30-
LAZ_OPT: '--build-mode=WIN32'
31-
ARTIFACT: 'libsimpleocr32.dll'
21+
fpcup-url: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.2g/fpclazup-i386-win32.exe'
22+
fpcup-opt: '--lazrevision=64339'
23+
fpc-url: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
24+
laz-url: 'trunk'
25+
build-mode: 'WIN32'
26+
binary: 'libsimpleocr32.dll'
3227

3328
- os: windows-latest
3429
name: 'Windows 64'
35-
FPCUP: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.0b/fpclazup-x86_64-win64.exe'
36-
FPC_VER: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
37-
LAZ_VER: 'trunk'
38-
LAZ_OPT: '--build-mode=WIN64'
39-
ARTIFACT: 'libsimpleocr64.dll'
30+
fpcup-url: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.2g/fpclazup-x86_64-win64.exe'
31+
fpcup-opt: '--lazrevision=64339'
32+
fpc-url: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
33+
laz-url: 'trunk'
34+
build-mode: 'WIN64'
35+
binary: 'libsimpleocr64.dll'
4036

4137
- os: ubuntu-latest
4238
name: 'Linux 64'
43-
FPCUP: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.0b/fpclazup-x86_64-linux'
44-
FPC_VER: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
45-
LAZ_VER: 'trunk'
46-
LAZ_OPT: '--build-mode=LINUX64'
47-
ARTIFACT: 'libsimpleocr64.so'
39+
fpcup-url: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.2g/fpclazup-x86_64-linux'
40+
fpcup-opt: '--lazrevision=64339'
41+
fpc-url: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
42+
laz-url: 'trunk'
43+
build-mode: 'LINUX64'
44+
binary: 'libsimpleocr64.so'
4845

4946
- os: macos-latest
5047
name: 'MacOS 64'
51-
FPCUP: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.0b/fpclazup-x86_64-darwin'
52-
FPCUP_OPT: '--lclplatform=cocoa'
53-
FPC_VER: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
54-
LAZ_VER: 'trunk'
55-
LAZ_OPT: '--build-mode=DARWIN64'
56-
ARTIFACT: 'libsimpleocr64.dylib'
48+
fpcup-url: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.2g/fpclazup-x86_64-darwin'
49+
fpcup-opt: '--lazrevision=64339'
50+
fpc-url: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
51+
laz-url: 'trunk'
52+
build-mode: 'DARWIN64'
53+
binary: 'libsimpleocr64.dylib'
5754

5855
- os: ubuntu-latest
5956
name: 'AArch64'
60-
FPCUP: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.0b/fpclazup-x86_64-linux'
61-
FPC_VER: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
62-
LAZ_VER: 'trunk'
63-
LAZ_OPT: '--build-mode=AARCH64'
64-
ARTIFACT: 'libsimpleocr64.so.aarch64'
57+
fpcup-url: 'https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.8.2g/fpclazup-x86_64-linux'
58+
fpcup-opt: '--lazrevision=64339'
59+
fpc-url: 'https://svn.freepascal.org/svn/fpc/tags/release_3_2_0'
60+
laz-url: 'trunk'
61+
build-mode: 'AARCH64'
62+
binary: 'libsimpleocr64.so.aarch64'
6563

6664
steps:
67-
- uses: actions/checkout@v2
65+
- uses: actions/checkout@v2.3.4
6866
with:
6967
submodules: true
7068

69+
- name: Install Dependencies (Ubuntu)
70+
if: matrix.config.os == 'ubuntu-latest'
71+
run: |
72+
sudo apt-get update
73+
sudo apt-get -y install libgtk2.0-dev gcc-aarch64-linux-gnu
74+
sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib
75+
7176
- name: Generate Cache Hash
72-
run: echo ${{ env.FPCUP }}${{ env.FPC_VER }}${{ env.LAZ_VER }}${{ env.NAME }} > cache
77+
run: echo "${{ matrix.config.fpcup-url }}${{ matrix.config.fpcup-opt }}${{ matrix.config.fpc-url }}${{ matrix.config.laz-url }}${{ matrix.config.name }}" > .cache
7378

7479
- name: Cache
7580
id: cache
76-
uses: actions/cache@v2.0.0
81+
uses: actions/cache@v2.1.4
7782
with:
78-
path: lazarus/
79-
key: ${{ hashFiles('cache') }}
80-
81-
- name: Install Dependencies
82-
if: env.OS == 'ubuntu-latest'
83-
shell: bash
84-
run: |
85-
sudo apt-get update
86-
sudo apt-get -y install libgtk2.0-dev gcc-aarch64-linux-gnu
87-
sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib
83+
path: lazarus
84+
key: ${{ hashFiles('.cache') }}
8885

8986
- name: Install Lazarus
9087
if: steps.cache.outputs.cache-hit != 'true'
91-
shell: bash
9288
run: |
93-
curl --retry 5 -L -o fpcup ${{ env.FPCUP }}
94-
mkdir lazarus || true
89+
curl --retry 5 -L -o fpcup ${{ matrix.config.fpcup-url }}
9590
chmod +x fpcup
96-
./fpcup --installdir=lazarus --fpcURL=${{ env.FPC_VER }} --lazURL=${{ env.LAZ_VER }} ${{ env.FPCUP_OPT }} --noconfirm --verbose
91+
mkdir lazarus
92+
./fpcup --installdir=lazarus --fpcURL=${{ matrix.config.fpc-url }} --lazURL=${{ matrix.config.laz-url }} ${{ matrix.config.fpcup-opt }} --only=docker --noconfirm --verbose
9793
9894
- name: Install AArch64 Cross Compiler
99-
if: steps.cache.outputs.cache-hit != 'true' && env.NAME == 'AArch64'
100-
shell: bash
101-
run: |
102-
curl --retry 5 -L -o libs.zip https://github.com/LongDirtyAnimAlf/fpcupdeluxe/releases/download/crosslibs_v1.1/CrossLibsLinuxAarch64.zip && unzip libs.zip -d lazarus/
103-
curl --retry 5 -L -o bins.zip https://github.com/LongDirtyAnimAlf/fpcupdeluxe/releases/download/linuxx64crossbins_v1.0/CrossBinsLinuxAarch64.zip && unzip bins.zip -d lazarus/cross/bin
95+
if: steps.cache.outputs.cache-hit != 'true' && matrix.config.name == 'AArch64'
96+
run: |
97+
curl --retry 5 -L -o libs.zip https://github.com/LongDirtyAnimAlf/fpcupdeluxe/releases/download/crosslibs_v1.1/CrossLibsLinuxAarch64.zip && unzip -o libs.zip -d lazarus/
98+
curl --retry 5 -L -o bins.zip https://github.com/LongDirtyAnimAlf/fpcupdeluxe/releases/download/linuxx64crossbins_v1.0/CrossBinsLinuxAarch64.zip && unzip -o bins.zip -d lazarus/cross/bin
10499
./fpcup --installdir=lazarus --ostarget=linux --cputarget=aarch64 --only="FPCCleanOnly,FPCBuildOnly" --crossbindir=lazarus/cross/bin --crosslibdir=lazarus/cross/lib/aarch64-linux --noconfirm --verbose
105100
106101
- name: Build SimpleOCR
107-
shell: bash
108102
run: |
109-
./lazarus/lazarus/lazbuild ${{ env.LAZ_OPT }} "SimpleOCR.lpi"
103+
./lazarus/lazarus/lazbuild --build-mode=${{ matrix.config.build-mode }} "SimpleOCR.lpi"
110104
111105
- name: Upload Artifact
112-
uses: actions/upload-artifact@v2.0.1
106+
uses: actions/upload-artifact@v2.2.2
113107
with:
114-
path: ${{ env.ARTIFACT }}
108+
path: ${{ matrix.config.binary }}
115109

116110
upload:
117111
runs-on: ubuntu-latest
@@ -120,15 +114,15 @@ jobs:
120114
uses: Brandon-T/wait-for-check-action@v1
121115
with:
122116
github_token: ${{ secrets.GITHUB_TOKEN }}
123-
check_names: '["Windows 32", "Windows 64", "Linux 64", "MacOS 64", "AArch64"]'
117+
check_names: '["Windows 32", "Windows 64", "Linux 64", "AArch64", "MacOS 64"]'
124118
statuses: '["completed", "completed", "completed", "completed", "completed"]'
125119
conclusions: '["success", "success", "success", "success", "success"]'
126120
timeout: 1500
127-
poll_interval: 10
121+
poll_interval: 5
128122

129123
- name: Download Artifacts
130124
if: github.event_name == 'push'
131-
uses: actions/download-artifact@v2
125+
uses: actions/download-artifact@v2.0.8
132126

133127
- name: Update Release
134128
if: github.event_name == 'push'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*.dylib
77
backup
88
lib
9+
*.res

README.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ Recognized: Climb-up Ladder / 2 more option
1919
## Exports
2020
2121
```pascal
22-
procedure TFontSet.Load(Font: String; Space: Int32 = 4);
23-
function TSimpleOCR.Recognize(constref AClient: T2DIntegerArray; Filter: TCompareRules; constref FontSet: TFontSet; IsStatic: Boolean = False; MaxWalk: Int32 = 40): String;
24-
function TSimpleOCR.Recognize(B: TBox; Filter: TCompareRules; constref Font: TFontSet; IsStatic: Boolean = False; MaxWalk: Int32 = 40): AnsiString;
22+
procedure TFontSet.Load(constref Font: String; constref Space: Int32 = 4);
23+
function TSimpleOCR.DrawText(constref Text: String; constref FontSet: TFontSet): T2DIntegerArray;
24+
function TSimpleOCR.Recognize(constref B: TBox; constref Filter: TCompareRules; constref Font: TFontSet; constref IsStatic: Boolean = False; constref MaxWalk: Int32 = 40): String; overload;
25+
function TSimpleOCR.RecognizeNumber(constref B: TBox; constref Filter: TCompareRules; constref Font: TFontSet; constref IsStatic: Boolean = False; constref MaxWalk: Int32 = 40): Int64;
26+
function TSimpleOCR.LocateText(constref B: TBox; constref Text: String; constref Font: TFontSet; constref Filter: TCompareRules; out Bounds: TBox): Single; overload;
27+
function TSimpleOCR.LocateText(constref B: TBox; constref Text: String; constref Font: TFontSet; constref Filter: TCompareRules; constref MinMatch: Single = 1): Boolean; overload;
2528
```
2629

2730
-----
@@ -30,13 +33,14 @@ function TSimpleOCR.Recognize(B: TBox; Filter: TCompareRules; constref Font: TFo
3033

3134
```pascal
3235
TCompareRules = packed record
33-
Color, Tolerance: Int32; // Color and tolerance. Color can be -1 to match any color.
34-
UseShadow: Boolean; // If the fontset has a shadow, it can be used to improve recognition.
35-
ShadowMaxValue: Int32; // Max brightness of shadow, Shadows are black so this is often low.
36-
Threshold: Boolean; // Threshold the image? If so all above fields are ignored.
37-
ThresholdAmount: Int32; // Threshold amount.
38-
ThresholdInvert: Boolean; // Threshold invert?
39-
MinCharacterMatch: Int32; // Minimum hits required to match a character. Useful to remove smaller characters (like dots) that are often misread.
36+
Color, Tolerance: Int32; // Color and tolerance. Color can be -1 to match any color.
37+
UseShadow: Boolean; // If the fontset has a shadow, it can be used to improve recognition.
38+
ShadowMaxValue: Int32; // Max brightness of shadow, Shadows are black so this is often low.
39+
Threshold: Boolean; // Threshold the image? If so all above fields are ignored.
40+
ThresholdAmount: Int32; // Threshold amount.
41+
ThresholdInvert: Boolean; // Threshold invert?
42+
UseShadowForColor: Boolean; // Find and offset shadows by (-1,-1) and use most common color to recognize text with.
43+
MinCharacterMatch: Int32; // Minimum hits required to match a character. Useful to remove smaller characters (like dots) that are often misread.
4044
end;
4145
```
4246

@@ -50,4 +54,10 @@ If the starting position (X1,Y1) of the text never changes the text is static wh
5054

5155
`MaxWalk` parameter:
5256

53-
How far the OCR looks on the X axis before giving up. By default this is `40` so if no characaters are matched in 40 pixels the function finishes.
57+
How far the OCR looks on the X axis before giving up. By default this is `40` so if no characaters are matched in 40 pixels the function finishes.
58+
59+
-----
60+
61+
`LocateText` function:
62+
63+
LocateText does not OCR! In simple terms a bitmap of the text is created (Using DrawText) and searched for. Color can be `-1` though each pixel of the text must be the exact same color.

SimpleOCR.lpi

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<TargetCPU Value="i386"/>
3737
<TargetOS Value="win32"/>
3838
<Optimizations>
39-
<OptimizationLevel Value="3"/>
39+
<OptimizationLevel Value="4"/>
4040
</Optimizations>
4141
</CodeGeneration>
4242
<Linking>
@@ -67,7 +67,7 @@
6767
<TargetCPU Value="x86_64"/>
6868
<TargetOS Value="linux"/>
6969
<Optimizations>
70-
<OptimizationLevel Value="3"/>
70+
<OptimizationLevel Value="4"/>
7171
</Optimizations>
7272
</CodeGeneration>
7373
<Linking>
@@ -101,7 +101,7 @@
101101
<TargetCPU Value="x86_64"/>
102102
<TargetOS Value="darwin"/>
103103
<Optimizations>
104-
<OptimizationLevel Value="3"/>
104+
<OptimizationLevel Value="4"/>
105105
</Optimizations>
106106
</CodeGeneration>
107107
<Linking>
@@ -132,7 +132,7 @@
132132
<TargetCPU Value="aarch64"/>
133133
<TargetOS Value="linux"/>
134134
<Optimizations>
135-
<OptimizationLevel Value="3"/>
135+
<OptimizationLevel Value="4"/>
136136
</Optimizations>
137137
</CodeGeneration>
138138
<Linking>
@@ -194,7 +194,7 @@
194194
<TargetCPU Value="x86_64"/>
195195
<TargetOS Value="win64"/>
196196
<Optimizations>
197-
<OptimizationLevel Value="3"/>
197+
<OptimizationLevel Value="4"/>
198198
</Optimizations>
199199
</CodeGeneration>
200200
<Linking>

0 commit comments

Comments
 (0)