|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Text recognition algorithm implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __HTI_TEXT_RCG_ |
|
20 #define __HTI_TEXT_RCG_ |
|
21 |
|
22 #include <fbs.h> |
|
23 #include <gulfont.h> |
|
24 #include <e32math.h> |
|
25 |
|
26 const TInt KDefaultAvgDiffMin = 50; |
|
27 const TInt KDefaultFgSSMin = 50; |
|
28 const TInt KDefaultFgAvgDiffMin = 5; //in "pure" (not AA) pixels |
|
29 const TInt KWorstCase = 0xFF; |
|
30 const TInt KSuccessThresold = 50; |
|
31 const TInt KNormCoefAcc = 2; |
|
32 |
|
33 const TInt KDefaultFGAAmount = 5; |
|
34 const TInt KDefaultBGAAmount = 10; |
|
35 |
|
36 const TInt KFgPatternColor = 0x00; //black |
|
37 const TInt KBgPatternColor = 0xff; //white |
|
38 |
|
39 TInt CompareTPoint(const TPoint& aP1,const TPoint& aP2); |
|
40 |
|
41 enum THtiTextRecgHints |
|
42 { |
|
43 EHintNone = 0, |
|
44 EHintEdge = 1 |
|
45 }; |
|
46 |
|
47 /** |
|
48 * The class implements text recognition algorithm on screenshots |
|
49 * based on system fonts |
|
50 * |
|
51 */ |
|
52 class CHtiTextRcg : public CBase |
|
53 { |
|
54 public: |
|
55 CHtiTextRcg(); |
|
56 virtual ~CHtiTextRcg(); |
|
57 |
|
58 void SetHint(TInt aHint); |
|
59 |
|
60 TBool RecognizeTextL(CFbsBitmap* aScreenshot, |
|
61 const TDesC& aText, |
|
62 const CFont* aFont, |
|
63 TRect& aResult); |
|
64 |
|
65 /** |
|
66 * aResult will contain the coordinates of the found text |
|
67 * Return 0 if match is perfect, 255 if text was not found |
|
68 * return value from 0 to 255 means some error, the lower it is the better match |
|
69 * |
|
70 */ |
|
71 //brute force optim |
|
72 TInt RecognizeAAL(CFbsBitmap* aScreenshot,const TDesC& aText, const CFont* aFont, TRect& aResult); |
|
73 //brute force clean optim |
|
74 TInt RecognizeBinL(CFbsBitmap* aScreenshot,const TDesC& aText, const CFont* aFont, TRect& aResult); |
|
75 |
|
76 //static image processing routines |
|
77 //convert image to 256-greyscale |
|
78 static CFbsBitmap* ColorDownL(CFbsBitmap * aBitmap); |
|
79 //generates bitmap of the text using the font given |
|
80 |
|
81 static CFbsBitmap* GetTextBitmapL( const TDesC& aText, |
|
82 const CFont* fontUsed, |
|
83 const TInt aLength = KMaxTInt ); |
|
84 |
|
85 static CFbsBitmap* GetTextBitmapL( const TDesC& aText, |
|
86 const CFont* fontUsed, |
|
87 TRgb aForeground, |
|
88 TRgb aBackground, |
|
89 TDisplayMode aDisplayMode, |
|
90 const TInt aLength = KMaxTInt ); |
|
91 |
|
92 //calculates min max of a greyscale bitmap in question |
|
93 static void MinMax(CFbsBitmap * aBitmap, TInt& aMin, TInt& aMax); |
|
94 |
|
95 /** |
|
96 * use FGA and BGA to speed-up comparation |
|
97 * this function only returns 255 or 0 |
|
98 * Analyses only min and max colors |
|
99 */ |
|
100 TInt ImageDiffBinSampleL(CFbsBitmap * aBitmap1, TPoint aOrigin1, |
|
101 CFbsBitmap * aBitmap2); |
|
102 |
|
103 /** |
|
104 * Iterations like in Diff5 but metrics from Diff6 |
|
105 * Used for full word checking if Diff6 is 0 for a letter |
|
106 * this function only returns 255 or 0 |
|
107 */ |
|
108 TInt ImageDiffBinFullL(CFbsBitmap * aBitmap1, TPoint aOrigin1, |
|
109 CFbsBitmap * aBitmap2); |
|
110 |
|
111 /** |
|
112 * use FGA and BGA to speed-up comparation and AA pixels |
|
113 */ |
|
114 TInt ImageDiffAASampleL(CFbsBitmap * aBitmap1, TPoint aOrigin1, |
|
115 CFbsBitmap * aBitmap2); |
|
116 |
|
117 /** |
|
118 * Iterations like in Diff5 but metrics from Diff6/DiffAASample |
|
119 * Used for full word checking if Diff6 is 0 for a letter |
|
120 */ |
|
121 TInt ImageDiffAAFullL(CFbsBitmap * aBitmap1, TPoint aOrigin1, |
|
122 CFbsBitmap * aBitmap2); |
|
123 |
|
124 /* |
|
125 * Analyze pattern and fills in FGA and BGA sets |
|
126 * Return ETrue if pattern is valid (non empty) |
|
127 */ |
|
128 TBool AnalyzePatternL(CFbsBitmap * aPattern); |
|
129 |
|
130 private: |
|
131 //algorithm parameters |
|
132 //minimal abs avarage difference beetwen foreground and background |
|
133 TInt iAvgDiffMin; |
|
134 //minimal SS for foreground, with plain color should be 0 |
|
135 TInt iFgSSMin; |
|
136 /** |
|
137 * minimal avg diff for foreground, used in Diff3 |
|
138 */ |
|
139 TInt iFgAvgDiffMin; |
|
140 |
|
141 //TInt64 iSeed; |
|
142 |
|
143 //following vars set by AnalyzePatternL |
|
144 TInt iFGAAmount; |
|
145 TInt iBGAAmount; |
|
146 //foreground assesment point set |
|
147 RArray<TPoint> iFGASet; |
|
148 //background assesment point set |
|
149 RArray<TPoint> iBGASet; |
|
150 |
|
151 //font color in reference image |
|
152 TInt iMaskFgColor;// |
|
153 //background color in reference image |
|
154 TInt iMaskBgColor;// |
|
155 |
|
156 //used for AA algorithm |
|
157 //set in Sample function and used in Full function |
|
158 //for optimization |
|
159 TInt iTestFgColor; |
|
160 TInt iTestBgColor; |
|
161 |
|
162 // normalization coeff to compare test image with mask directly |
|
163 // |iMaskFgColor-iMaskBgColor|*NormCoefAcc)/|iTestFgColor-iTestBgColor| |
|
164 // where NormCoefAcc multiplyer is used to increase accuracy (all ints) |
|
165 // and is implemented as shif by KNormCoefAcc bits |
|
166 // back shift is performed after color is multiplied by iTestNormCoef |
|
167 TInt iTestNormCoef; |
|
168 |
|
169 /** |
|
170 * Current recognition method |
|
171 * Changed by SetHint |
|
172 */ |
|
173 TInt iCurrentStrategy; |
|
174 }; |
|
175 |
|
176 #endif //__HTI_TEXT_RCG_ |
|
177 |
|
178 // End of file |