1.1 --- a/epoc32/include/mw/ocrsrv.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/mw/ocrsrv.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,469 @@
1.4 -ocrsrv.h
1.5 +/*
1.6 +* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* 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
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description: APIs of the OCR(Optical Character Recognition), current engine
1.19 +* can recognize 24 bit colored image and 8 bit gray scale image
1.20 +* in BMP format.And the size of images are also limited within
1.21 +* 1600x1200 in pixel
1.22 +*
1.23 +*
1.24 +*/
1.25 +
1.26 +
1.27 +#ifndef OCRSRV_H
1.28 +#define OCRSRV_H
1.29 +
1.30 +// INCLUDE FILES
1.31 +#include <ocrcommon.h>
1.32 +
1.33 +// Constants
1.34 +
1.35 +//class declaration
1.36 +class OCREngineFactory;
1.37 +
1.38 +/**
1.39 + * OCR (Optical Character Recognition) Engine Observer
1.40 + *
1.41 + * This set of interfaces defines the observers of the OCR engine. This is the unique set
1.42 + * for all types of engines. User needs to implement a concrete class which is derived from
1.43 + * this class.
1.44 + *
1.45 + * @lib ocrsrv.lib
1.46 + * @since S60 3.1
1.47 + */
1.48 +class MOCREngineObserver
1.49 + {
1.50 + public:
1.51 + /**
1.52 + * This interface will be called after the Block Recognition is completed. This calling
1.53 + * only valid when using the EEngineRecognizeBlock type of engine
1.54 + * @see OCREngineFactory::TEngineType
1.55 + * @see MOCREngineRecognizeBlock
1.56 + *
1.57 + * @since S60 3.1
1.58 + * @param aError Error code to indicate the completion status
1.59 + * @param aBlocks Pointer to the text information of the recognized image block, Please note
1.60 + that the memory ownership belongs to the OCR engine and will not be passed
1.61 + to your procedure after this calling
1.62 + * @param aBlockCount Number of block identified
1.63 + * @return None
1.64 + */
1.65 + virtual void RecognizeBlockComplete(TInt aError,
1.66 + const TOCRTextRgnInfo* aBlocks,
1.67 + const TInt aBlockCount) = 0;
1.68 +
1.69 + /**
1.70 + * This interface will be called after the Special Region Recognition is completed. This calling
1.71 + * only valid when using the EEngineRecognizeBlock type of engine
1.72 + * @see OCREngineFactory::TEngineType
1.73 + * @see MOCREngineRecognizeBlock
1.74 + *
1.75 + * @since S60 3.1
1.76 + * @param aError Error code to indicate the completion status
1.77 + * @param aBlocks Pointer to the text information of the recognized image block, Please note
1.78 + that the memory ownership belongs to the OCR engine and will not be passed
1.79 + to your procedure after this calling
1.80 + * @param aBlockCount Number of block identified
1.81 + * @return None
1.82 + */
1.83 + virtual void RecognizeSpecialRegionComplete(TInt aError,
1.84 + const TOCRTextRgnInfo* aBlocks,
1.85 + const TInt aBlockCount) = 0;
1.86 +
1.87 + /**
1.88 + * This interface will be called after the Full Image Recognition is completed. This calling
1.89 + * only valid when using the EEngineLayoutRecognize type of engine
1.90 + * @see OCREngineFactory::TEngineType
1.91 + * @see MOCREngineLayoutRecognize
1.92 + *
1.93 + * @since S60 3.1
1.94 + * @param aError Error code to indicate the completion status
1.95 + * @param aBlocks Pointer to the text information of the recognized image block, Please note
1.96 + that the memory ownership belongs to the OCR engine and will not be passed
1.97 + to your procedure after this calling
1.98 + * @param aBlockCount Number of block identified
1.99 + * @return None
1.100 + */
1.101 + virtual void RecognizeComplete(TInt aError,
1.102 + const TOCRTextRgnInfo* aBlocks,
1.103 + const TInt aBlockCount) = 0;
1.104 +
1.105 + /**
1.106 + * This interface will be called after the Full Image Layout Analysis is completed. This calling
1.107 + * only valid when using the EEngineLayoutRecognize type of engine
1.108 + * @see OCREngineFactory::TEngineType
1.109 + * @see MOCREngineLayoutRecognize
1.110 + *
1.111 + * @since S60 3.1
1.112 + * @param aError Error code to indicate the completion status
1.113 + * @param aBlocks Pointer to the text information of the recognized image block, Please note
1.114 + that the memory ownership belongs to the OCR engine and will not be passed
1.115 + to your procedure after this calling
1.116 + * @param aBlockCount Number of block identified
1.117 + * @return None
1.118 + */
1.119 + virtual void LayoutComplete(TInt aError,
1.120 + const TOCRBlockInfo* aBlocks,
1.121 + const TInt aBlockCount) = 0;
1.122 +
1.123 + /**
1.124 + * This interface will be called during the procession and indicates the progress.
1.125 + *
1.126 + * @since S60 3.1
1.127 + * @param aPercent A percentage of the current progression
1.128 + * @return None
1.129 + */
1.130 + virtual void RecognizeProcess(const TUint aPercent) = 0;
1.131 + };
1.132 +
1.133 +
1.134 +/**
1.135 + * OCR (Optical Character Recognition) Engine Base
1.136 + *
1.137 + * Base class of the OCR engine, this offers definitions of the features which
1.138 + * all engines shall give support
1.139 + *
1.140 + * @lib ocrsrv.lib
1.141 + * @since S60 3.1
1.142 + */
1.143 +class MOCREngineBase
1.144 + {
1.145 + public:
1.146 +
1.147 + /**
1.148 + * Get the current version of the OCR interfaces
1.149 + *
1.150 + * @since S60 3.1
1.151 + * @return Current version
1.152 + */
1.153 + virtual TVersion GetVersion() const = 0;
1.154 +
1.155 + /**
1.156 + * This interface refreshes the installed language packages. The OCR engine
1.157 + * supports the languages to be installed as SIS packages and can be installed
1.158 + * or uninstalled dynamically. This method shall be called after changes made
1.159 + * on the installed language packages
1.160 + *
1.161 + * @leave KErrNotFound No OCR engine found
1.162 + * @since S60 3.1
1.163 + * @return None
1.164 + */
1.165 + virtual void RefreshInstalledLanguageL() = 0;
1.166 +
1.167 + /**
1.168 + * This method sets the languages for the recognition, maximum 2 languages can
1.169 + * be passed together, regardless of their position in the array
1.170 + *
1.171 + * @since S60 3.1
1.172 + * @param aActiveLanguage Array of specified languages @see GetInstalledLanguage
1.173 + * @return None
1.174 + *
1.175 + * @leave KErrArgument Language count is more than two
1.176 + * @leave KErrNotSupported The language is not supported by current OCR engine
1.177 + * @leave KErrOcrBadLanguage Unsupported language
1.178 + * @leave KErrOcrBadDictFile Not set any language packages
1.179 + */
1.180 + virtual void SetActiveLanguageL(const RArray<TLanguage>& aActiveLanguage) = 0;
1.181 +
1.182 + /**
1.183 + * This method gets the languages which are currently installed and supported
1.184 + *
1.185 + * @since S60 3.1
1.186 + * @param aLanguages Array of installed languages @see SetActiveLanguageL
1.187 + * @return None
1.188 + */
1.189 + virtual void GetInstalledLanguage(RArray<TLanguage>& aLanguages) const = 0;
1.190 +
1.191 + /**
1.192 + * This method cancels the recognition
1.193 + * Call to this method the process will be terminated, and a KErrCancel flag
1.194 + * will be passed to MOCREngineObserver's observers and through the aError
1.195 + * parameter. Call this method when the engine is not working will not take
1.196 + * any effect, this method internally calls IsEngineActive method
1.197 + * @see MOCREngineObserver
1.198 + *
1.199 + * @since S60 3.1
1.200 + * @return None
1.201 + */
1.202 + virtual void CancelOperation() = 0;
1.203 +
1.204 + /**
1.205 + * This method judges whether a language is supported
1.206 + *
1.207 + * @since S60 3.1
1.208 + * @param aLanguage A language specifed
1.209 + * @return ETrue if supported; EFalse otherwise
1.210 + */
1.211 + virtual TBool IsLanguageSupported(const TLanguage aLanguage) = 0;
1.212 +
1.213 + /**
1.214 + * This method tests whether the engine is working or not
1.215 + * Typically you could call this method to test whether there is
1.216 + * an outstanding request or not.
1.217 + * Note that when you are trying to exit the application when
1.218 + * there's an outstanding issue, you should first call this method
1.219 + * and call CancelOperation method before really terminate the
1.220 + * client application
1.221 + *
1.222 + * @since S60 3.1
1.223 + * @return ETrue if the engine is working; EFalse otherwise
1.224 + */
1.225 + virtual TBool IsEngineActive() const = 0;
1.226 + };
1.227 +
1.228 +
1.229 +/**
1.230 + * OCR (Optical Character Recognition) Engine Interface Base
1.231 + *
1.232 + * Base interfaces for the OCR engine, all engines derived from this class
1.233 + * User can access base features from Base method
1.234 + *
1.235 + * @lib ocrsrv.lib
1.236 + * @since S60 3.1
1.237 + */
1.238 +class MOCREngineInterface
1.239 + {
1.240 + public:
1.241 +
1.242 + /**
1.243 + * This method gets the MOCREngineBase interface, user can access base features
1.244 + * from this method
1.245 + *
1.246 + * @since S60 3.1
1.247 + * @return Pointer to the engine base @see MOCREngineBase
1.248 + */
1.249 + virtual MOCREngineBase* Base() const = 0;
1.250 +
1.251 + /**
1.252 + * Virtual destructor
1.253 + */
1.254 + virtual ~MOCREngineInterface() { };
1.255 + };
1.256 +
1.257 +
1.258 +/**
1.259 + * OCR (Optical Character Recognition) Engine Interfaces with Layout Analysis
1.260 + *
1.261 + * This set of interfaces offers the OCR engine which supports Layout Analysis
1.262 + * on full images. User shall pass the handle of the image through LayoutAnalysisL
1.263 + * first, and then pass block ids to RecognizeL to complete the recognition.
1.264 + *
1.265 + * For Example:
1.266 + * After passing the image handle to LayoutAnalysisL, the MOCREngineObserver::LayoutComplete
1.267 + * will be called after the process. Then through the TOCRBlockInfo array (const TOCRBlockInfo* aBlock
1.268 + * and const TInt aBlockCount), the user knows how many blocks have been identified
1.269 + * together with their position information. Those blocks are marked with ids from Zero to
1.270 + * aBlockCount - 1.
1.271 + *
1.272 + * Then the user must specify which blocks are going to be further processed (Note that layout analysis
1.273 + * only gets you the position of those blocks, but does not recognize the characters inside each block).
1.274 + * The const RArray<TInt>& aBlock in MOCREngineLayoutRecognize::RecognizeL saves all the ids that are
1.275 + * selected to be further processed. e.g. if you have 10 blocks from LayoutComplete, you can append
1.276 + * 1, 3, 5, 7 to the TInt array and pass it to RecognizeL
1.277 + *
1.278 + * Note that this class shall be used together with TEngineType set to EEngineLayoutRecognize
1.279 + *
1.280 + * @lib ocrsrv.lib
1.281 + * @since S60 3.1
1.282 + */
1.283 +class MOCREngineLayoutRecognize : public MOCREngineInterface
1.284 + {
1.285 + public:
1.286 +
1.287 + /**
1.288 + * This method does the layout analysis for the full image
1.289 + *
1.290 + * @since S60 3.1
1.291 + * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
1.292 + * @param aSettings Settings for layout analysis @see TOCRLayoutSetting
1.293 + * @return None
1.294 + *
1.295 + * @leave KErrNotSupported Image shall be in BMP format (24bit colored or 8 bit grayscale)
1.296 + * and the size shall not exceed 1600x1200 in pixel
1.297 + * @leave KErrNotReady Internal object is not constructed
1.298 + * @leave KErrAbort Child thread does not exist or operation is aborted
1.299 + * @leave KErrServerBusy OCR service is busy
1.300 + */
1.301 + virtual void LayoutAnalysisL(const TInt aBitmapHandle,
1.302 + const TOCRLayoutSetting aSettings) = 0;
1.303 +
1.304 + /**
1.305 + * This method does the character recognition for the image on base of the result from
1.306 + * LayoutAnalysisL
1.307 + *
1.308 + * @since S60 3.1
1.309 + * @param aSettings Settings for recognition
1.310 + * @param aBlockIdsToRecognize Block Ids to be recognized
1.311 + * @return None
1.312 + *
1.313 + * @leave KErrNotReady Internal object is not constructed
1.314 + * @leave KErrAbort Child thread does not exist or operation is aborted
1.315 + * @leave KErrArgument Bolck information is available
1.316 + *
1.317 + */
1.318 + virtual void RecognizeL(const TOCRRecognizeSetting aSettings,
1.319 + const RArray<TInt>& aBlockIdsToRecognize) = 0;
1.320 + };
1.321 +
1.322 +/**
1.323 + * OCR (Optical Character Recognition) Engine Interfaces without Layout Analysis
1.324 + *
1.325 + * This set of interfaces offers the OCR engine which does not support Layout Analysis
1.326 + * on full images. User shall implement their own layout solution
1.327 + *
1.328 + * RecognizeBlockL recognizes text information in a single block area regardless of content
1.329 + *
1.330 + * RecognizeSpecialRegionL recognizes text information in a single block area and its content
1.331 + * sensitive. User can select three different types of contents: e-mail address, phone numbers
1.332 + * or web addresses @see TRegionInfo
1.333 + *
1.334 + * Note that this class shall be used together with TEngineType set to EEngineRecognizeBlock
1.335 + *
1.336 + * @lib ocrsrv.lib
1.337 + * @since S60 3.1
1.338 + */
1.339 +class MOCREngineRecognizeBlock : public MOCREngineInterface
1.340 + {
1.341 + public:
1.342 +
1.343 + /**
1.344 + * This method recognizes text in a single block
1.345 + *
1.346 + * @since S60 3.1
1.347 + * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
1.348 + * @param aLayoutInfo Block information
1.349 + * @return None
1.350 + *
1.351 + * @leave KErrNotSupported Image shall be in BMP format (24bit colored or 8 bit grayscale)
1.352 + * and the size shall not exceed 1600x1200 in pixel
1.353 + * @leave KErrNotReady Internal object is not constructed
1.354 + * @leave KErrAbort Child thread does not exist or operation is aborted
1.355 + * @leave KErrCouldNotConnect No connection to the font and bitmap server could be made
1.356 + * @leave KErrUnknown No bitmap could be found with the specified handle number
1.357 + * @leave KErrArgument aRegionInfo is available
1.358 + * @leave KErrServerBusy OCR service is busy
1.359 + */
1.360 + virtual void RecognizeBlockL(const TInt aBitmapHandle,
1.361 + const TOCRLayoutBlockInfo aLayoutInfo) = 0;
1.362 +
1.363 + /**
1.364 + * This method recognizes text with special content in a single block
1.365 + *
1.366 + * Note that SetActiveLanguageL has to be called first and language must be set to TLanguage::ELangEnglish
1.367 + *
1.368 + * @since S60 3.1
1.369 + * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
1.370 + * @param aRegionInfo Block information
1.371 + * @return None
1.372 + *
1.373 + * @leave KErrNotSupported Image shall be in BMP format (24bit colored or 8 bit grayscale)
1.374 + * and the size shall not exceed 1600x1200 in pixel
1.375 + * @leave KErrNotReady Internal object is not constructed
1.376 + * @leave KErrAbort Child thread does not exist or operation is aborted
1.377 + * @leave KErrCouldNotConnect No connection to the font and bitmap server could be made
1.378 + * @leave KErrUnknown No bitmap could be found with the specified handle number
1.379 + * @leave KErrArgument aRegionInfo is available
1.380 + * @leave KErrServerBusy OCR service is busy
1.381 + */
1.382 + virtual void RecognizeSpecialRegionL(const TInt aBitmapHandle,
1.383 + const TRegionInfo aRegionInfo) = 0;
1.384 + };
1.385 +
1.386 +/**
1.387 + * OCR (Optical Character Recognition) API
1.388 + *
1.389 + * This static class offers the OCR APIs. The user shall call CreateOCREngineL
1.390 + * and get the instance of one type of the OCR engine and then convert the instance
1.391 + * from MOCREngineInterface to MOCREngineLayoutRecognize or MOCREngineRecognizeBlock
1.392 + * according to the type information. And use ReleaseOCREngine to destroy the engine.
1.393 + * @see OCREngineFactory::TEngineType
1.394 + *
1.395 + * Note: This procedure will create a new thread in your current process in order to
1.396 + * run the OCR APIs, so you don't need to create new threads for OCR by yourself
1.397 + *
1.398 + * For example:
1.399 + * A typical usage for the factory class would be like:
1.400 + * @code
1.401 + * const TOcrEngineEnv env;
1.402 + * env.iPriority = EPriorityLess;
1.403 + * env.iMaxHeapSize = 1200*KMinHeapGrowBy;
1.404 + * MOCREngineInterface* myEngine = CreateOCREngineL( aObserver, env, EEngineLayoutRecognize);
1.405 + * MOCREngineLayoutRecognize* layoutEngine = STATIC_CAST( MOCREngineLayoutRecognize*, myEngine );
1.406 + * // TODO: call coresponding methods in layoutEngine
1.407 + * ReleaseOCREngine( layoutEngine );
1.408 + * @endcode
1.409 + * @lib ocrsrv.lib
1.410 + * @since S60 3.1
1.411 + */
1.412 +class OCREngineFactory
1.413 + {
1.414 + public:
1.415 + /**
1.416 + * OCR Engine Types
1.417 + */
1.418 + enum TEngineType
1.419 + {
1.420 + /**
1.421 + * OCR Engine with layout analysis feature:
1.422 + * by selecting this type of engine, LayoutAnalysisL
1.423 + * shall be called first before RecognizeL.
1.424 + */
1.425 + EEngineLayoutRecognize,
1.426 +
1.427 + /**
1.428 + * Engine without layout analysis feature:
1.429 + * Layout information shall be passed through TOCRLayoutBlockInfo
1.430 + * or TRegionInfo to the interfaces
1.431 + */
1.432 + EEngineRecognizeBlock
1.433 +
1.434 + };
1.435 +
1.436 + public:
1.437 +
1.438 + /**
1.439 + * Create the OCR engine instance
1.440 + *
1.441 + * @since S60 3.1
1.442 + * @param aObserver Pointer to the call callback function
1.443 + * @param aEngineEnv Engine environment settings @see TOcrEngineEnv
1.444 + * @param aEngineType Select a type of engine to be created @see OCREngineFactory::TEngineType
1.445 + * @return Pointer to the engine created @see MOCREngineInterface
1.446 + *
1.447 + * @leave KErrArgument aEngineEnv.iMaxHeapSize is lower(equal) than KMinHeapGrowBy*1000
1.448 + * @leave KErrNotSupported aEngineType is not supported
1.449 + */
1.450 + IMPORT_C static MOCREngineInterface* CreateOCREngineL(MOCREngineObserver& aObserver,
1.451 + const TOcrEngineEnv aEngineEnv,
1.452 + TEngineType aEngineType);
1.453 +
1.454 + /**
1.455 + * Release the OCR engine instance
1.456 + *
1.457 + * @since S60 3.1
1.458 + * @param aEng Pointer to the instance of the Engine
1.459 + * @return None
1.460 + */
1.461 + IMPORT_C static void ReleaseOCREngine(MOCREngineInterface* aEng);
1.462 +
1.463 + private:
1.464 +
1.465 + /**
1.466 + * Constructor
1.467 + */
1.468 + OCREngineFactory();
1.469 + };
1.470 +
1.471 +#endif // OCRSRV_H
1.472 +
1.473 +// End of file