|
RecAPI
|
Letter handling tools. More...
Topics | |
| LETTER::fontAttrib field elements | |
| Possible values of LETTER::fontAttrib field. | |
| LETTER::info field macros | |
| Macros can be used with LETTER::info field. | |
| Info field bits | |
| Possible flags of LETTER::info field. | |
| LETTER::makeup field elements | |
Flags of end-position LETTERs (see usage of them in the table) and direction/orientation flags (see also the section about vertical text support). | |
| Space type values | |
| Possible space types (LSPC). | |
| Macros of alternatives of the LETTER | |
| Macros can be used for processing the alternatives of each LETTER. See also usage of usage of alternatives. | |
| Defines of confidence handling of the LETTER | |
| See confidence handling and LETTER::err. | |
Classes | |
| struct | LSPC |
| Additional information about the space character. More... | |
| struct | LETTER |
| The LETTER structure. More... | |
Typedefs | |
| typedef LETTER * | LPLETTER |
| Pointer to a structure LETTER. | |
| typedef const LETTER * | LPCLETTER |
| Const pointer to a structure LETTER. | |
Enumerations | |
| enum | LETTERSTRENGTH { LTS_FINAL , LTS_STRONG , LTS_MEDIUM , LTS_WEAK , LTS_SIZE } |
| Possible places where letter array is to be copied to. More... | |
Functions | |
| RECERR RECAPIKRN | kRecGetLetters (HPAGE hPage, IMAGEINDEX iiImage, LPLETTER *ppLetter, LPLONG pLettersLength) |
| Getting recognition result. | |
| RECERR RECAPIKRN | kRecGetLetterPalette (HPAGE hPage, REC_COLOR **ppColours, LPLONG pNum) |
| Getting palette of recognition data. | |
| RECERR RECAPIKRN | kRecGetChoiceStr (HPAGE hPage, WCHAR **ppChoices, LPLONG pLength) |
| Getting choices. | |
| RECERR RECAPIKRN | kRecGetSuggestionStr (HPAGE hPage, WCHAR **ppSuggestions, LPLONG pLength) |
| Getting suggestions. | |
| RECERR RECAPIKRN | kRecGetFontFaceStr (HPAGE hPage, char **ppFontFaces, LPLONG pLength) |
| Getting font faces. | |
| RECERR RECAPIKRN | kRecSetLetters (LETTERSTRENGTH towhere, HPAGE hPage, IMAGEINDEX iiImage, LPCLETTER pLetter, LONG LettersLength) |
Putting a letter buffer onto the input of the PLUS2W and PLUS3W engines or the selected output converter. | |
| RECERR RECAPIKRN | kRecFreeRecognitionData (HPAGE hPage) |
| Freeing recognition data. | |
Letter handling tools.
Recognized data is stored in the current HPAGE and it is available as an array of LETTER structures providing significantly more information than the character code itself. This type of output offers the most detailed information on recognition. The information stored in a LETTER structure may belong to the character itself (character code, position, size, confidence level, font attributes, font face, choices, color) or to the word containing the character (suggestions, languages). Word-level information is set in the first LETTER of the word.
NOTE: In both the SDK and its documentation, coordinates refer to grid-coordinates - i.e. the top or left borders of pixels. Thus a rectangle does not contain the pixels according to its right and bottom coordinates.
Spaces have a special role in the text, thus their handling is also special. There are two kinds of spaces in the recognition result.
One of them is the space-like character. It really appears in the original text and it is represented with a LETTER having a space character in its code field and an LSPC structure containing information about this character. The SPACE and TAB characters and the leaders belong to this type. The spcCount field of LSPC cotains the number of characters encoded as this single "space" code. Note that spcCount can be 0 also, meaning an unspecified number of spaces. (It could be treated as 1 space.)
The other kind of space is the dummy space. It does not appear in the original text, but it has an individual LETTER object. A special feature of this character is that its width is 0. This dummy space indicates the end of the line, the R_ENDOFLINE flag is added to this dummy character.
In rare cases, there is no dummy character at the end of a line: it may happen only when the last character in the line is a hyphen. The lack of the dummy space indicates that the last word of this line and the first word of the next line should be logically combined to a single hyphenated word. The R_ENDOFLINE flag is placed on the hyphen in this case. (Note that the info field's RR_SOFTHYPHEN bit is true for such hyphens.)
Barcode module (BAR) has a special binary recognition mode, when the recognition result contains binary data (not a text). (See the setting Kernel.OcrMgr.BarBinary and binary output section for more information.) In this case the content of the barcode is logically one word in one line, but a dummy end-of-line space is appended even to that sequence.
The last letter (maybe punctuation character or digit) of a word is the LETTER having an R_ENDOFWORD flag. The beginning of a word is the first non-space character after the previous word (or the very first item of the LETTER array). The flag R_ENDOFLINE does not play a role in determining word boundaries (e.g. hyphenation).
Special cases:
R_ENDOFWORD flag is on the character before the dash. This kind of dash is not marked with RR_SOFTHYPHEN even if the dash is at end of line.R_ENDOFWORD before the hyphen. The hyphen's LETTER::info field has the RR_SOFTHYPHEN flag.Word-related information (like the language of a word or RE_SUSPECT_WORD, etc.) is specified on all the characters of the word. The only exception is suggestion handling where suggestions are attached to the first character of the word only. (Note that suggestion handling uses a different word notion: space-separated words.)
The letters in ending positions are marked with particular flags. See above section for details about end of word. The end of line flag in a flowing text is generally on the above mentioned dummy space. However, if the last character of a line is a hyphen in a hyphenated word, the flag R_ENDOFLINE is placed on the hyphen and the dummy space is missing from this line.
In a table the situation of end-position flags is more difficult. The next figure shows all the possible situations of the R_ENDOFLINE (L), R_ENDOFCELL (C), R_ENDOFROW (R) and R_ENDOFZONE (Z) flags in a table.
| text L,C | text L,C | text L,C,R |
| text L,C | more L lines in L a cell L,C,R | |
| two-line L text L,C | text L,C,R | |
| last filled L cell L,C,R,Z |
The R_ENDOFLINE_CR and R_ENDOFLINE_LF flags may supplement the R_ENDOFLINE flag. They are placed only on a barcode's end-position letters (that are dummy spaces) when the barcode has multiple lines. These flags indicate what kind of EOL code is encoded in the barcode at that position (CR: 0x0d, LF: 0x0a, or the CRLF: 0x0d 0x0a sequence).
Barcode data may also contain runs of EOL codes, i.e. empty lines. In the LETTER array it is implemented as multiple dummy spaces (in normal, non-binary mode). Each dummy space has the R_ENDOFLINE flag with the above supplementary CR and/or LF flags.
The common name for LETTER choices and word suggestions is 'alternatives'. You can use different alternatives similarly. They can be accessed through special WCHAR typed arrays. Every single alternative is a special string with its size in its 0th WCHAR element and an ending zero WCHAR. You can get WCHAR arrays listing of all alternatives in the recognition data - one for choices and one for suggestions. Use the functions kRecGetChoiceStr, and kRecGetSuggestionStr, respectively.
One LETTER contains an index to the list of the alternatives that points to its first alternative and has a counter with the number of its alternatives. All LETTERs can have choices (LETTER::ndxChoices), but only the first LETTER of a word refers to the suggestions (LETTER::ndxSuggestions). The scope of such a suggestion is the space-terminated word. (Note that it can differ from the end of the word notion used by spelling.)
The alternatives of a LETTER can be enumerated using the macros GETFIRSTALTERN, GETNEXTALTERN and GETALTERNLENGTH. See the following sample code on how to use them:
Consecutive words can have the same suggestion indices - that is, the given suggestions are common to the group of the given words. This is the case when the suggestion combines two space-separated words into a single one without the space.
Since the first LETTER of a word cannot be a space, spaces do not have suggestions, but they have space information (LSPC) in the same union type (see above for more information about space handling).
Font faces can be accessed in a string of C-type strings. The LETTER indexes into this string at the first character of its font face name.
| enum LETTERSTRENGTH |
Possible places where letter array is to be copied to.
| Enumerator | |
|---|---|
| LTS_FINAL | Letters are put directly onto the input of the output conversion step. |
| LTS_STRONG | Letters are put onto the strong input of the |
| LTS_MEDIUM | Letters are put onto the medium input of the |
| LTS_WEAK | Letters are put onto the weak input of the |
| LTS_SIZE | Number of LETTER indices (for verifying index validity). |
Freeing recognition data.
The kRecFreeRecognitionData function destroys the recognized data (memory object) belonging to the hPage page.
| [in] | hPage | Handle of the page having the data to be removed. |
| RECERR |
Getting choices.
The kRecGetChoiceStr function makes the alternative letter choices data belonging to the hPage page available to the application by creating a new memory object. This function can be called after a successful kRecRecognize call. The retrieved data is available as an array of WCHAR structures. For more about its internal structure see the usage of alternatives. A LETTER contains the number of its choices and an index into this array on the first choice (LETTER::cntChoices, LETTER::ndxChoices).
| [in] | hPage | Handle of the page whose recognized data should be accessed. |
| [out] | ppChoices | Address of a pointer variable to get the array of the recognized alternative characters and ligatures. |
| [out] | pLength | Pointer to a variable to hold the length of recognized alternative characters. |
| RECERR |
Getting font faces.
The kRecGetFontFaceStr function makes the font face data belonging to the hPage page available to the application by creating a new memory object. This function can be called after a successful kRecRecognize call. The retrieved data is available as an array of char strings. A LETTER contains an index into this array on its font face (LETTER::ndxFontFace).
| [in] | hPage | Handle of the page whose recognized data should be accessed. |
| [out] | ppFontFaces | Address of a pointer variable to get the UTF-8 string of the recognized font faces. |
| [out] | pLength | Pointer to a variable to hold the length of recognized font face string. |
| RECERR |
Getting palette of recognition data.
This function makes the palette of the recognition data belonging to the hPage page available to the application by creating a new memory object. This function can be called after a successful kRecRecognize call. It contains both the foreground and background colors of the letters. The LETTER structure has indices into this array for foreground and background colors (LETTER::ndxFGColor, LETTER::ndxBGColor).
| [in] | hPage | Handle of the page whose recognized data should be accessed. |
| [out] | ppColours | Address of a pointer variable to get the address of the palette array. |
| [out] | pNum | Pointer to a variable to hold the number of colors in palette. |
| RECERR |
REC_DEFAULT_COLOR, which means black. | RECERR RECAPIKRN kRecGetLetters | ( | HPAGE | hPage, |
| IMAGEINDEX | iiImage, | ||
| LPLETTER * | ppLetter, | ||
| LPLONG | pLettersLength ) |
Getting recognition result.
The kRecGetLetters function makes the recognition data belonging to the hPage page available to the application by creating a new memory object containing the recognized data. This function can be called after a successful kRecRecognize call. The recognized data is available as an array of LETTER structures.
| [in] | hPage | Handle of the page whose recognized data should be accessed. |
| [in] | iiImage | Index of the image in the page, in which the coordinates are needed to be given. |
| [out] | ppLetter | Address of a pointer variable to get the address of the recognized characters. |
| [out] | pLettersLength | Pointer to a variable to hold the number of recognized characters. |
| RECERR |
Getting suggestions.
The kRecGetSuggestionStr function makes the word suggestions data belonging to the hPage page available to the application by creating a new memory object. This function can be called after a successful kRecRecognize call. The retrieved data is available as an array of WCHAR structures. For more about its internal structure see the usage of alternatives. The first LETTER of a word contains the number of word choices and an index into this array on the first suggestion (LETTER::cntSuggestions, LETTER::ndxSuggestions).
| [in] | hPage | Handle of the page whose recognized data should be accessed. |
| [out] | ppSuggestions | Address of a pointer variable to get the array of the recognized suggestions. |
| [out] | pLength | Pointer to a variable to hold the length of recognized suggestions. |
| RECERR |
| RECERR RECAPIKRN kRecSetLetters | ( | LETTERSTRENGTH | towhere, |
| HPAGE | hPage, | ||
| IMAGEINDEX | iiImage, | ||
| LPCLETTER | pLetter, | ||
| LONG | LettersLength ) |
Putting a letter buffer onto the input of the PLUS2W and PLUS3W engines or the selected output converter.
This function can affect the recognition results and/or the content of the output file. The PLUS modules are voting engines combining results of two or three other OCR engines. The voting method of RM_OMNIFONT_PLUS2W has strong and medium inputs, RM_OMNIFONT_PLUS3W uses an additional weak one as well. You can replace one input (parameter towhere) with your alternative engine result by calling the function kRecSetLetters. The voting method uses your letter buffer as it generates the final OCR result. Stronger input may have greater effect on the recognition result, so you should consider which level you select for your letter buffer.
Passing the letter buffer on the level LTS_FINAL the OCR method does not run, because in this level kRecSetLetters works similarly as in previous versions of CSDK, i.e. the letters are given directly to the input of the selected output converter.
| [in] | towhere | This parameter specifies one of the three possible inputs of the Voting Engine, on which the engine receives the letter buffer. |
| [in] | hPage | Handle of the HPAGE the Voting Engine works on. |
| [in] | iiImage | Index of the image in the page whose coordinate system you have used in defining the boundary box for LETTER. |
| [in] | pLetter | The letter buffer to be given to the engine. |
| [in] | LettersLength | Size of the letter buffer. |
| RECERR |
LTS_FINAL), you should call kRecRecognize. PLUS engines can be replaced with subsequent calls for kRecSetLetters. Even in such a case, kRecRecognize should be called only once. kRecRecognize: cntChoices, ndxChoices, cntSuggestions, ndxSuggestions, reserved_b, ndxFGColor, ndxBGColor, ndxFontFace, ndxExt and OCRENGINE bits (RH_OCRENGINE_MASK) of info. These fields are cleared and the original order of LETTERs may be altered after using this function.