epoc32/include/mw/ocrsrv.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2 * Copyright (c) 2002-2005 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:  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
    17 *                1600x1200 in pixel
    18 *
    19 *
    20 */
    21 
    22  
    23 #ifndef OCRSRV_H
    24 #define OCRSRV_H
    25 
    26 //  INCLUDE FILES
    27 #include <ocrcommon.h>
    28 
    29 //  Constants
    30 
    31 //class declaration
    32 class OCREngineFactory;
    33 
    34 /**
    35  *  OCR (Optical Character Recognition) Engine Observer
    36  *
    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
    39  *  this class.
    40  *
    41  *  @lib ocrsrv.lib
    42  *  @since S60 3.1
    43  */
    44 class MOCREngineObserver  
    45     {
    46     public:    
    47         /**
    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
    52          *
    53          * @since S60 3.1
    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
    59          * @return None
    60          */  
    61         virtual void RecognizeBlockComplete(TInt aError, 
    62                                             const TOCRTextRgnInfo* aBlocks, 
    63                                             const TInt aBlockCount) = 0;
    64         
    65         /**
    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 
    70          *
    71          * @since S60 3.1
    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
    77          * @return None
    78          */  
    79         virtual void RecognizeSpecialRegionComplete(TInt aError, 
    80                                                     const TOCRTextRgnInfo* aBlocks, 
    81                                                     const TInt aBlockCount) = 0;
    82      
    83         /**
    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
    88          *
    89          * @since S60 3.1
    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
    95          * @return None
    96          */
    97         virtual void RecognizeComplete(TInt aError, 
    98                                        const TOCRTextRgnInfo* aBlocks, 
    99                                        const TInt aBlockCount) = 0;
   100 
   101         /**
   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
   106          *
   107          * @since S60 3.1
   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
   113          * @return None
   114          */
   115         virtual void LayoutComplete(TInt aError, 
   116                                     const TOCRBlockInfo* aBlocks, 
   117                                     const TInt aBlockCount) = 0;
   118 
   119         /**
   120          * This interface will be called during the procession and indicates the progress.
   121          *
   122          * @since S60 3.1
   123          * @param aPercent A percentage of the current progression
   124          * @return None
   125          */
   126         virtual void RecognizeProcess(const TUint aPercent) = 0;
   127     };
   128 
   129 
   130 /**
   131  *  OCR (Optical Character Recognition) Engine Base
   132  *
   133  *  Base class of the OCR engine, this offers definitions of the features which
   134  *  all engines shall give support
   135  *
   136  *  @lib ocrsrv.lib
   137  *  @since S60 3.1
   138  */
   139 class MOCREngineBase  
   140     {
   141     public:
   142     
   143         /**
   144          * Get the current version of the OCR interfaces
   145          *
   146          * @since S60 3.1
   147          * @return Current version
   148          */
   149         virtual TVersion GetVersion() const = 0;
   150 
   151         /**
   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
   156          *
   157          * @leave KErrNotFound No OCR engine found
   158          * @since S60 3.1
   159          * @return None
   160          */
   161         virtual void RefreshInstalledLanguageL() = 0;
   162 
   163         /**
   164          * This method sets the languages for the recognition, maximum 2 languages can
   165          * be passed together, regardless of their position in the array
   166          *
   167          * @since S60 3.1         
   168          * @param aActiveLanguage Array of specified languages @see GetInstalledLanguage
   169          * @return None
   170          *
   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
   175          */
   176         virtual void SetActiveLanguageL(const RArray<TLanguage>& aActiveLanguage) = 0;
   177 
   178         /**
   179          * This method gets the languages which are currently installed and supported
   180          *
   181          * @since S60 3.1         
   182          * @param aLanguages Array of installed languages @see SetActiveLanguageL
   183          * @return None
   184          */
   185         virtual void GetInstalledLanguage(RArray<TLanguage>& aLanguages) const = 0;
   186 
   187         /**
   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
   194          *
   195          * @since S60 3.1         
   196          * @return None
   197          */
   198         virtual void CancelOperation() = 0;
   199 
   200         /**
   201          * This method judges whether a language is supported
   202          *
   203          * @since S60 3.1 
   204          * @param aLanguage A language specifed    
   205          * @return ETrue if supported; EFalse otherwise
   206          */
   207         virtual TBool IsLanguageSupported(const TLanguage aLanguage) = 0;
   208         
   209         /**
   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 
   216          * client application
   217          *
   218          * @since S60 3.1  
   219          * @return ETrue if the engine is working; EFalse otherwise
   220          */
   221          virtual TBool IsEngineActive() const = 0;
   222     };
   223 
   224 
   225 /**
   226  *  OCR (Optical Character Recognition) Engine Interface Base
   227  *
   228  *  Base interfaces for the OCR engine, all engines derived from this class
   229  *  User can access base features from Base method
   230  *
   231  *  @lib ocrsrv.lib
   232  *  @since S60 3.1
   233  */
   234 class MOCREngineInterface
   235     {
   236     public:
   237     
   238         /**
   239          * This method gets the MOCREngineBase interface, user can access base features
   240          * from this method
   241          *
   242          * @since S60 3.1 
   243          * @return Pointer to the engine base @see MOCREngineBase
   244          */
   245         virtual MOCREngineBase* Base() const = 0;
   246         
   247         /**
   248         * Virtual destructor
   249         */
   250         virtual ~MOCREngineInterface() { };
   251     };
   252 
   253 
   254 /**
   255  *  OCR (Optical Character Recognition) Engine Interfaces with Layout Analysis
   256  *
   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.
   260  *  
   261  *  For Example:
   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 
   266  *  aBlockCount - 1. 
   267  *
   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
   273  *
   274  *  Note that this class shall be used together with TEngineType set to EEngineLayoutRecognize
   275  *
   276  *  @lib ocrsrv.lib
   277  *  @since S60 3.1
   278  */
   279 class MOCREngineLayoutRecognize : public MOCREngineInterface
   280     { 
   281     public:
   282     
   283         /**
   284          * This method does the layout analysis for the full image
   285          *
   286          * @since S60 3.1         
   287          * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
   288          * @param aSettings Settings for layout analysis @see TOCRLayoutSetting
   289          * @return None
   290          *
   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
   296          */
   297         virtual void LayoutAnalysisL(const TInt aBitmapHandle, 
   298                                      const TOCRLayoutSetting aSettings) = 0;
   299 
   300         /**
   301          * This method does the character recognition for the image on base of the result from 
   302          * LayoutAnalysisL
   303          *
   304          * @since S60 3.1         
   305          * @param aSettings Settings for recognition
   306          * @param aBlockIdsToRecognize Block Ids to be recognized
   307          * @return None
   308          *
   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        
   312          * 
   313          */
   314         virtual void RecognizeL(const TOCRRecognizeSetting aSettings, 
   315                                 const RArray<TInt>& aBlockIdsToRecognize) = 0;
   316     };
   317 
   318 /**
   319  *  OCR (Optical Character Recognition) Engine Interfaces without Layout Analysis
   320  *
   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
   323  *  
   324  *  RecognizeBlockL recognizes text information in a single block area regardless of content
   325  *
   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
   329  *
   330  *  Note that this class shall be used together with TEngineType set to EEngineRecognizeBlock
   331  *
   332  *  @lib ocrsrv.lib
   333  *  @since S60 3.1
   334  */
   335 class MOCREngineRecognizeBlock : public MOCREngineInterface
   336     {
   337     public:
   338     
   339         /**
   340          * This method recognizes text in a single block
   341          *
   342          * @since S60 3.1         
   343          * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
   344          * @param aLayoutInfo Block information
   345          * @return None
   346          *
   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 
   355          */
   356         virtual void RecognizeBlockL(const TInt aBitmapHandle, 
   357                                      const TOCRLayoutBlockInfo aLayoutInfo) = 0;
   358 
   359         /**
   360          * This method recognizes text with special content in a single block
   361          *
   362          * Note that SetActiveLanguageL has to be called first and language must be set to TLanguage::ELangEnglish
   363          *
   364          * @since S60 3.1         
   365          * @param aBitmapHandle Handle of the image(get from CFbsBitmap::Handle())
   366          * @param aRegionInfo Block information
   367          * @return None
   368          *
   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 
   377          */
   378         virtual void RecognizeSpecialRegionL(const TInt aBitmapHandle, 
   379                                              const TRegionInfo aRegionInfo) = 0;
   380     };
   381 
   382 /**
   383  *  OCR (Optical Character Recognition) API
   384  *
   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
   390  * 
   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
   393  *
   394  *  For example:
   395  *  A typical usage for the factory class would be like:
   396  *  @code
   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 );
   404  *  @endcode
   405  *  @lib ocrsrv.lib
   406  *  @since S60 3.1
   407  */
   408 class OCREngineFactory  
   409     {
   410     public:   
   411         /**  
   412         * OCR Engine Types 
   413         */
   414         enum TEngineType 
   415             {
   416             /**
   417             * OCR Engine with layout analysis feature:
   418             * by selecting this type of engine, LayoutAnalysisL
   419             * shall be called first before RecognizeL. 
   420             */
   421             EEngineLayoutRecognize,      
   422                                      
   423             /**
   424             * Engine without layout analysis feature:
   425             * Layout information shall be passed through TOCRLayoutBlockInfo
   426             * or TRegionInfo to the interfaces
   427             */                            
   428             EEngineRecognizeBlock        
   429                                          
   430             };  
   431               
   432     public: 
   433     
   434         /**
   435          * Create the OCR engine instance 
   436          *
   437          * @since S60 3.1
   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
   442          * 
   443          * @leave KErrArgument aEngineEnv.iMaxHeapSize is lower(equal) than KMinHeapGrowBy*1000 
   444          * @leave KErrNotSupported aEngineType is not supported 
   445          */    
   446         IMPORT_C static MOCREngineInterface* CreateOCREngineL(MOCREngineObserver& aObserver, 
   447                                                               const TOcrEngineEnv aEngineEnv, 
   448                                                               TEngineType aEngineType); 
   449 
   450         /**
   451          * Release the OCR engine instance
   452          *
   453          * @since S60 3.1
   454          * @param aEng Pointer to the instance of the Engine
   455          * @return None
   456          */ 
   457         IMPORT_C static void ReleaseOCREngine(MOCREngineInterface* aEng);
   458         
   459     private:
   460         
   461         /**
   462         * Constructor
   463         */
   464         OCREngineFactory();
   465     };
   466 
   467 #endif  // OCRSRV_H
   468 
   469 // End of file