2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: APIs of the OCR(Optical Character Recognition), current engine
15 * can recognize 24 bit colored image and 8 bit gray scale image
16 * in BMP format.And the size of images are also limited within
27 #include <ocrcommon.h>
32 class OCREngineFactory;
35 * OCR (Optical Character Recognition) Engine Observer
37 * This set of interfaces defines the observers of the OCR engine. This is the unique set
38 * for all types of engines. User needs to implement a concrete class which is derived from
44 class MOCREngineObserver
48 * This interface will be called after the Block Recognition is completed. This calling
49 * only valid when using the EEngineRecognizeBlock type of engine
50 * @see OCREngineFactory::TEngineType
51 * @see MOCREngineRecognizeBlock
54 * @param aError Error code to indicate the completion status
55 * @param aBlocks Pointer to the text information of the recognized image block, Please note
56 that the memory ownership belongs to the OCR engine and will not be passed
57 to your procedure after this calling
58 * @param aBlockCount Number of block identified
61 virtual void RecognizeBlockComplete(TInt aError,
62 const TOCRTextRgnInfo* aBlocks,
63 const TInt aBlockCount) = 0;
66 * This interface will be called after the Special Region Recognition is completed. This calling
67 * only valid when using the EEngineRecognizeBlock type of engine
68 * @see OCREngineFactory::TEngineType
69 * @see MOCREngineRecognizeBlock
72 * @param aError Error code to indicate the completion status
73 * @param aBlocks Pointer to the text information of the recognized image block, Please note
74 that the memory ownership belongs to the OCR engine and will not be passed
75 to your procedure after this calling
76 * @param aBlockCount Number of block identified
79 virtual void RecognizeSpecialRegionComplete(TInt aError,
80 const TOCRTextRgnInfo* aBlocks,
81 const TInt aBlockCount) = 0;
84 * This interface will be called after the Full Image Recognition is completed. This calling
85 * only valid when using the EEngineLayoutRecognize type of engine
86 * @see OCREngineFactory::TEngineType
87 * @see MOCREngineLayoutRecognize
90 * @param aError Error code to indicate the completion status
91 * @param aBlocks Pointer to the text information of the recognized image block, Please note
92 that the memory ownership belongs to the OCR engine and will not be passed
93 to your procedure after this calling
94 * @param aBlockCount Number of block identified
97 virtual void RecognizeComplete(TInt aError,
98 const TOCRTextRgnInfo* aBlocks,
99 const TInt aBlockCount) = 0;
102 * This interface will be called after the Full Image Layout Analysis is completed. This calling
103 * only valid when using the EEngineLayoutRecognize type of engine
104 * @see OCREngineFactory::TEngineType
105 * @see MOCREngineLayoutRecognize
108 * @param aError Error code to indicate the completion status
109 * @param aBlocks Pointer to the text information of the recognized image block, Please note
110 that the memory ownership belongs to the OCR engine and will not be passed
111 to your procedure after this calling
112 * @param aBlockCount Number of block identified
115 virtual void LayoutComplete(TInt aError,
116 const TOCRBlockInfo* aBlocks,
117 const TInt aBlockCount) = 0;
120 * This interface will be called during the procession and indicates the progress.
123 * @param aPercent A percentage of the current progression
126 virtual void RecognizeProcess(const TUint aPercent) = 0;
131 * OCR (Optical Character Recognition) Engine Base
133 * Base class of the OCR engine, this offers definitions of the features which
134 * all engines shall give support
144 * Get the current version of the OCR interfaces
147 * @return Current version
149 virtual TVersion GetVersion() const = 0;
152 * This interface refreshes the installed language packages. The OCR engine
153 * supports the languages to be installed as SIS packages and can be installed
154 * or uninstalled dynamically. This method shall be called after changes made
155 * on the installed language packages
157 * @leave KErrNotFound No OCR engine found
161 virtual void RefreshInstalledLanguageL() = 0;
164 * This method sets the languages for the recognition, maximum 2 languages can
165 * be passed together, regardless of their position in the array
168 * @param aActiveLanguage Array of specified languages @see GetInstalledLanguage
171 * @leave KErrArgument Language count is more than two
172 * @leave KErrNotSupported The language is not supported by current OCR engine
173 * @leave KErrOcrBadLanguage Unsupported language
174 * @leave KErrOcrBadDictFile Not set any language packages
176 virtual void SetActiveLanguageL(const RArray<TLanguage>& aActiveLanguage) = 0;
179 * This method gets the languages which are currently installed and supported
182 * @param aLanguages Array of installed languages @see SetActiveLanguageL
185 virtual void GetInstalledLanguage(RArray<TLanguage>& aLanguages) const = 0;
188 * This method cancels the recognition
189 * Call to this method the process will be terminated, and a KErrCancel flag
190 * will be passed to MOCREngineObserver's observers and through the aError
191 * parameter. Call this method when the engine is not working will not take
192 * any effect, this method internally calls IsEngineActive method
193 * @see MOCREngineObserver
198 virtual void CancelOperation() = 0;
201 * This method judges whether a language is supported
204 * @param aLanguage A language specifed
205 * @return ETrue if supported; EFalse otherwise
207 virtual TBool IsLanguageSupported(const TLanguage aLanguage) = 0;
210 * This method tests whether the engine is working or not
211 * Typically you could call this method to test whether there is
212 * an outstanding request or not.
213 * Note that when you are trying to exit the application when
214 * there's an outstanding issue, you should first call this method
215 * and call CancelOperation method before really terminate the
219 * @return ETrue if the engine is working; EFalse otherwise
221 virtual TBool IsEngineActive() const = 0;
226 * OCR (Optical Character Recognition) Engine Interface Base
228 * Base interfaces for the OCR engine, all engines derived from this class
229 * User can access base features from Base method
234 class MOCREngineInterface
239 * This method gets the MOCREngineBase interface, user can access base features
243 * @return Pointer to the engine base @see MOCREngineBase
245 virtual MOCREngineBase* Base() const = 0;
250 virtual ~MOCREngineInterface() { };
255 * OCR (Optical Character Recognition) Engine Interfaces with Layout Analysis
257 * This set of interfaces offers the OCR engine which supports Layout Analysis
258 * on full images. User shall pass the handle of the image through LayoutAnalysisL
259 * first, and then pass block ids to RecognizeL to complete the recognition.
262 * After passing the image handle to LayoutAnalysisL, the MOCREngineObserver::LayoutComplete
263 * will be called after the process. Then through the TOCRBlockInfo array (const TOCRBlockInfo* aBlock
264 * and const TInt aBlockCount), the user knows how many blocks have been identified
265 * together with their position information. Those blocks are marked with ids from Zero to
268 * Then the user must specify which blocks are going to be further processed (Note that layout analysis
269 * only gets you the position of those blocks, but does not recognize the characters inside each block).
270 * The const RArray<TInt>& aBlock in MOCREngineLayoutRecognize::RecognizeL saves all the ids that are
271 * selected to be further processed. e.g. if you have 10 blocks from LayoutComplete, you can append
272 * 1, 3, 5, 7 to the TInt array and pass it to RecognizeL
274 * Note that this class shall be used together with TEngineType set to EEngineLayoutRecognize
279 class MOCREngineLayoutRecognize : public MOCREngineInterface
284 * This method does the layout analysis for the full image
287 * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
288 * @param aSettings Settings for layout analysis @see TOCRLayoutSetting
291 * @leave KErrNotSupported Image shall be in BMP format (24bit colored or 8 bit grayscale)
292 * and the size shall not exceed 1600x1200 in pixel
293 * @leave KErrNotReady Internal object is not constructed
294 * @leave KErrAbort Child thread does not exist or operation is aborted
295 * @leave KErrServerBusy OCR service is busy
297 virtual void LayoutAnalysisL(const TInt aBitmapHandle,
298 const TOCRLayoutSetting aSettings) = 0;
301 * This method does the character recognition for the image on base of the result from
305 * @param aSettings Settings for recognition
306 * @param aBlockIdsToRecognize Block Ids to be recognized
309 * @leave KErrNotReady Internal object is not constructed
310 * @leave KErrAbort Child thread does not exist or operation is aborted
311 * @leave KErrArgument Bolck information is available
314 virtual void RecognizeL(const TOCRRecognizeSetting aSettings,
315 const RArray<TInt>& aBlockIdsToRecognize) = 0;
319 * OCR (Optical Character Recognition) Engine Interfaces without Layout Analysis
321 * This set of interfaces offers the OCR engine which does not support Layout Analysis
322 * on full images. User shall implement their own layout solution
324 * RecognizeBlockL recognizes text information in a single block area regardless of content
326 * RecognizeSpecialRegionL recognizes text information in a single block area and its content
327 * sensitive. User can select three different types of contents: e-mail address, phone numbers
328 * or web addresses @see TRegionInfo
330 * Note that this class shall be used together with TEngineType set to EEngineRecognizeBlock
335 class MOCREngineRecognizeBlock : public MOCREngineInterface
340 * This method recognizes text in a single block
343 * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
344 * @param aLayoutInfo Block information
347 * @leave KErrNotSupported Image shall be in BMP format (24bit colored or 8 bit grayscale)
348 * and the size shall not exceed 1600x1200 in pixel
349 * @leave KErrNotReady Internal object is not constructed
350 * @leave KErrAbort Child thread does not exist or operation is aborted
351 * @leave KErrCouldNotConnect No connection to the font and bitmap server could be made
352 * @leave KErrUnknown No bitmap could be found with the specified handle number
353 * @leave KErrArgument aRegionInfo is available
354 * @leave KErrServerBusy OCR service is busy
356 virtual void RecognizeBlockL(const TInt aBitmapHandle,
357 const TOCRLayoutBlockInfo aLayoutInfo) = 0;
360 * This method recognizes text with special content in a single block
362 * Note that SetActiveLanguageL has to be called first and language must be set to TLanguage::ELangEnglish
365 * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
366 * @param aRegionInfo Block information
369 * @leave KErrNotSupported Image shall be in BMP format (24bit colored or 8 bit grayscale)
370 * and the size shall not exceed 1600x1200 in pixel
371 * @leave KErrNotReady Internal object is not constructed
372 * @leave KErrAbort Child thread does not exist or operation is aborted
373 * @leave KErrCouldNotConnect No connection to the font and bitmap server could be made
374 * @leave KErrUnknown No bitmap could be found with the specified handle number
375 * @leave KErrArgument aRegionInfo is available
376 * @leave KErrServerBusy OCR service is busy
378 virtual void RecognizeSpecialRegionL(const TInt aBitmapHandle,
379 const TRegionInfo aRegionInfo) = 0;
383 * OCR (Optical Character Recognition) API
385 * This static class offers the OCR APIs. The user shall call CreateOCREngineL
386 * and get the instance of one type of the OCR engine and then convert the instance
387 * from MOCREngineInterface to MOCREngineLayoutRecognize or MOCREngineRecognizeBlock
388 * according to the type information. And use ReleaseOCREngine to destroy the engine.
389 * @see OCREngineFactory::TEngineType
391 * Note: This procedure will create a new thread in your current process in order to
392 * run the OCR APIs, so you don't need to create new threads for OCR by yourself
395 * A typical usage for the factory class would be like:
397 * const TOcrEngineEnv env;
398 * env.iPriority = EPriorityLess;
399 * env.iMaxHeapSize = 1200*KMinHeapGrowBy;
400 * MOCREngineInterface* myEngine = CreateOCREngineL( aObserver, env, EEngineLayoutRecognize);
401 * MOCREngineLayoutRecognize* layoutEngine = STATIC_CAST( MOCREngineLayoutRecognize*, myEngine );
402 * // TODO: call coresponding methods in layoutEngine
403 * ReleaseOCREngine( layoutEngine );
408 class OCREngineFactory
417 * OCR Engine with layout analysis feature:
418 * by selecting this type of engine, LayoutAnalysisL
419 * shall be called first before RecognizeL.
421 EEngineLayoutRecognize,
424 * Engine without layout analysis feature:
425 * Layout information shall be passed through TOCRLayoutBlockInfo
426 * or TRegionInfo to the interfaces
428 EEngineRecognizeBlock
435 * Create the OCR engine instance
438 * @param aObserver Pointer to the call callback function
439 * @param aEngineEnv Engine environment settings @see TOcrEngineEnv
440 * @param aEngineType Select a type of engine to be created @see OCREngineFactory::TEngineType
441 * @return Pointer to the engine created @see MOCREngineInterface
443 * @leave KErrArgument aEngineEnv.iMaxHeapSize is lower(equal) than KMinHeapGrowBy*1000
444 * @leave KErrNotSupported aEngineType is not supported
446 IMPORT_C static MOCREngineInterface* CreateOCREngineL(MOCREngineObserver& aObserver,
447 const TOcrEngineEnv aEngineEnv,
448 TEngineType aEngineType);
451 * Release the OCR engine instance
454 * @param aEng Pointer to the instance of the Engine
457 IMPORT_C static void ReleaseOCREngine(MOCREngineInterface* aEng);