Nicomsoft OCR: Developer's Guide |
C++: | int Img_GetBlockCnt(HIMG ImgObj) |
C#: | int Img_GetBlockCnt(int ImgObj) |
Visual Basic: | Function Img_GetBlockCnt(ByVal ImgObj As Integer) As Integer |
Java: | int Img_GetBlockCnt(HIMG ImgObj) |
Delphi: | function Img_GetBlockCnt(ImgObj:HIMG):integer |
ImgObj [IN] – the Image object. |
int CfgObj, OcrObj, ImgObj, BlkObj, res, bcnt, lcnt, wcnt, i, j, k, n, Xpos, Ypos, Width, Height; wchar_t* txt; Engine_InitializeAdvanced(&CfgObj, &OcrObj, &ImgObj); //initialize OCR engine, create objects and load configuration res = Img_LoadFile(ImgObj, L"c:\\sample.bmp"); //load some image for OCR if (res > ERROR_FIRST) {}; //insert error handler here res = Img_OCR(ImgObj, OCRSTEP_FIRST, OCRSTEP_LAST, OCRFLAG_NONE); //perform OCR if (res > ERROR_FIRST) {}; //insert error handler here bcnt = Img_GetBlockCnt(ImgObj); //get number of zones for (i = 0; i < bcnt; i++) { Img_GetBlock(ImgObj, i, &BlkObj); //get Block object res = Blk_GetType(BlkObj); //get zone type Blk_GetRect(BlkObj, &Xpos, &Ypos, &Width, &Height); //get zone position and size res = Blk_Inversion(BlkObj, BLK_INVERSE_GET); //get zone inversion res = Blk_Rotation(BlkObj, BLK_ROTATE_GET); //get zone rotation res = Blk_Mirror(BlkObj, BLK_MIRROR_GET); //get zone mirror flag res = Blk_GetBackgroundColor(BlkObj); //get zone background color n = Blk_GetText(BlkObj, NULL, 0, FMT_EDITCOPY) + 1; //get buffer size plus terminating NULL character txt = (wchar_t*) malloc(sizeof(wchar_t) * n); //allocate memory for text Blk_GetText(BlkObj, txt, n, FMT_EDITCOPY); //get zone text //...use "txt" value now free(txt); //free memory lcnt = Blk_GetLineCnt(BlkObj); //get number of text lines for zone for (j = 0; j < lcnt; j++) { Blk_GetTextRect(BlkObj, j, -1, &Xpos, &Ypos, &Width, &Height); //get text line position and size n = Blk_GetLineText(BlkObj, j, NULL, 0) + 1; //get buffer size plus terminating NULL character txt = (wchar_t*) malloc(sizeof(wchar_t) * n); //allocate memory for text Blk_GetLineText(BlkObj, j, txt, n); //get line text //...use "txt" value now free(txt); //free memory wcnt = Blk_GetWordCnt(BlkObj, j); //get number of words of "j"-th text line of zone for (k = 0; k < wcnt; k++) { Blk_GetTextRect(BlkObj, j, k, &Xpos, &Ypos, &Width, &Height); //get word position and size res = Blk_GetWordFontColor(BlkObj, j, k); //get word font color res = Blk_GetWordFontSize(BlkObj, j, k); //get word font size res = Blk_GetWordFontStyle(BlkObj, j, k); //get word font style res = Blk_GetWordQual(BlkObj, j, k); //get word quality res = Blk_IsWordInDictionary(BlkObj, j, k); //check if this word is in dictionary n = Blk_GetWordText(BlkObj, j, k, NULL, 0) + 1; //get buffer size plus terminating NULL character txt = (wchar_t*) malloc(sizeof(wchar_t) * n); //allocate memory for text Blk_GetWordText(BlkObj, j, k, txt, n); //get word text //...use "txt" value now free(txt); //free memory } } } Engine_Uninitialize(); //release all created objects and uninitialize OCR engine
//assume reference to NSOCR COM was added using NSOCR_NameSpace; //Add NSOCR namespace from "NSOCR.cs" file //... int CfgObj, OcrObj, ImgObj, BlkObj, res, bcnt, lcnt, wcnt, i, j, k, Xpos, Ypos, Width, Height; string txt; NSOCRLib.NSOCRClass NsOCR = new NSOCRLib.NSOCRClass(); //create NSOCR COM object instance NsOCR.Engine_InitializeAdvanced(out CfgObj, out OcrObj, out ImgObj); //initialize OCR engine, create objects and load configuration res = NsOCR.Img_LoadFile(ImgObj, "c:\\sample.bmp"); //load some image for OCR if (res > TNSOCR.ERROR_FIRST) {}; //insert error handler here res = NsOCR.Img_OCR(ImgObj, TNSOCR.OCRSTEP_FIRST, TNSOCR.OCRSTEP_LAST, TNSOCR.OCRFLAG_NONE); //perform OCR if (res > TNSOCR.ERROR_FIRST) {}; //insert error handler here bcnt = NsOCR.Img_GetBlockCnt(ImgObj); //get number of zones for (i = 0; i < bcnt; i++) { NsOCR.Img_GetBlock(ImgObj, i, out BlkObj); //get Block object res = NsOCR.Blk_GetType(BlkObj); //get zone type NsOCR.Blk_GetRect(BlkObj, out Xpos, out Ypos, out Width, out Height); //get zone position and size res = NsOCR.Blk_Inversion(BlkObj, TNSOCR.BLK_INVERSE_GET); //get zone inversion res = NsOCR.Blk_Rotation(BlkObj, TNSOCR.BLK_ROTATE_GET); //get zone rotation res = NsOCR.Blk_Mirror(BlkObj, TNSOCR.BLK_MIRROR_GET); //get zone mirror flag res = NsOCR.Blk_GetBackgroundColor(BlkObj); //get zone background color NsOCR.Blk_GetText(BlkObj, out txt, TNSOCR.FMT_EDITCOPY); //get zone text lcnt = NsOCR.Blk_GetLineCnt(BlkObj); //get number of text lines for zone for (j = 0; j < lcnt; j++) { NsOCR.Blk_GetTextRect(BlkObj, j, -1, out Xpos, out Ypos, out Width, out Height); //get text line position and size NsOCR.Blk_GetLineText(BlkObj, j, out txt); //get line text wcnt = NsOCR.Blk_GetWordCnt(BlkObj, j); //get number of words of "j"-th text line of zone for (k = 0; k < wcnt; k++) { NsOCR.Blk_GetTextRect(BlkObj, j, k, out Xpos, out Ypos, out Width, out Height); //get word position and size res = NsOCR.Blk_GetWordFontColor(BlkObj, j, k); //get word font color res = NsOCR.Blk_GetWordFontSize(BlkObj, j, k); //get word font size res = NsOCR.Blk_GetWordFontStyle(BlkObj, j, k); //get word font style res = NsOCR.Blk_GetWordQual(BlkObj, j, k); //get word quality res = NsOCR.Blk_IsWordInDictionary(BlkObj, j, k); //check if this word is in dictionary NsOCR.Blk_GetWordText(BlkObj, j, k, out txt); //get word text } } } NsOCR.Engine_Uninitialize(); //release all created objects and uninitialize OCR engine
'assume reference to NSOCR COM was added 'assume "NSOCR.vb" file was added to project Dim CfgObj, OcrObj, ImgObj, BlkObj, res, bcnt, lcnt, wcnt, i, j, k, Xpos, Ypos, Width, Height As Integer Dim txt As String = "" Dim NsOCR As New NSOCRLib.NSOCRClass 'create NSOCR COM object instance NsOCR.Engine_InitializeAdvanced(CfgObj, OcrObj, ImgObj) 'initialize OCR engine, create objects and load configuration res = NsOCR.Img_LoadFile(ImgObj, "c:\sample.bmp") 'load some image for OCR If res > TNSOCR.ERROR_FIRST Then 'insert error handler here End If res = NsOCR.Img_OCR(ImgObj, TNSOCR.OCRSTEP_FIRST, TNSOCR.OCRSTEP_LAST, TNSOCR.OCRFLAG_NONE) 'perform OCR If res > TNSOCR.ERROR_FIRST Then 'insert error handler here End If bcnt = NsOCR.Img_GetBlockCnt(ImgObj) 'get number of zones For i = 0 To bcnt - 1 NsOCR.Img_GetBlock(ImgObj, i, BlkObj) 'get Block object res = NsOCR.Blk_GetType(BlkObj) 'get zone type NsOCR.Blk_GetRect(BlkObj, Xpos, Ypos, Width, Height) 'get zone position and size res = NsOCR.Blk_Inversion(BlkObj, TNSOCR.BLK_INVERSE_GET) 'get zone inversion res = NsOCR.Blk_Rotation(BlkObj, TNSOCR.BLK_ROTATE_GET) 'get zone rotation res = NsOCR.Blk_Mirror(BlkObj, TNSOCR.BLK_MIRROR_GET) 'get zone mirror flag res = NsOCR.Blk_GetBackgroundColor(BlkObj) 'get zone background color NsOCR.Blk_GetText(BlkObj, txt, TNSOCR.FMT_EDITCOPY) 'get zone text lcnt = NsOCR.Blk_GetLineCnt(BlkObj) 'get number of text lines for zone For j = 0 To lcnt - 1 NsOCR.Blk_GetTextRect(BlkObj, j, -1, Xpos, Ypos, Width, Height) 'get text line position and size NsOCR.Blk_GetLineText(BlkObj, j, txt) 'get line text wcnt = NsOCR.Blk_GetWordCnt(BlkObj, j) 'get number of words of "j"-th text line of zone For k = 0 To wcnt - 1 NsOCR.Blk_GetTextRect(BlkObj, j, k, out Xpos, out Ypos, out Width, out Height) 'get word position and size res = NsOCR.Blk_GetWordFontColor(BlkObj, j, k) 'get word font color res = NsOCR.Blk_GetWordFontSize(BlkObj, j, k) 'get word font size res = NsOCR.Blk_GetWordFontStyle(BlkObj, j, k) 'get word font style res = NsOCR.Blk_GetWordQual(BlkObj, j, k) 'get word quality res = NsOCR.Blk_IsWordInDictionary(BlkObj, j, k) 'check if this word is in dictionary NsOCR.Blk_GetWordText(BlkObj, j, k, txt) 'get word text Next k Next j Next i NsOCR.Engine_Uninitialize() 'release all created objects and uninitialize OCR engine
//assume NSOCR package was included //Java VM option "-Djava.library.path" must point to "Bin" folder (x86 platform) or to "Bin_64" folder (x64 platform) //... NSOCR.HCFG CfgObj = new NSOCR.HCFG(); NSOCR.HOCR OcrObj = new NSOCR.HOCR(); NSOCR.HIMG ImgObj = new NSOCR.HIMG(); NSOCR.HBLK BlkObj = new NSOCR.HBLK(); int res, bcnt, lcnt, wcnt, i, j, k; NSOCR.NSInt Xpos = new NSOCR.NSInt(0); NSOCR.NSInt Ypos = new NSOCR.NSInt(0); NSOCR.NSInt Width = new NSOCR.NSInt(0); NSOCR.NSInt Height = new NSOCR.NSInt(0); StringBuffer txt = new StringBuffer(); NSOCR.Engine.Engine_InitializeAdvanced(CfgObj, OcrObj, ImgObj); //initialize OCR engine, create objects and load configuration res = NSOCR.Engine.Img_LoadFile(ImgObj, "c:\\sample.bmp"); //load some image for OCR if (res > NSOCR.Error.ERROR_FIRST) {}; //insert error handler here res = NSOCR.Engine.Img_OCR(ImgObj, NSOCR.Constant.OCRSTEP_FIRST, NSOCR.Constant.OCRSTEP_LAST, NSOCR.Constant.OCRFLAG_NONE); //perform some OCR steps, stop before autozoning step if (res > NSOCR.Error.ERROR_FIRST) {}; //insert error handler here bcnt = NSOCR.Engine.Img_GetBlockCnt(ImgObj); //get number of zones for (i = 0; i < bcnt; i++) { NSOCR.Engine.Img_GetBlock(ImgObj, i, BlkObj); //get Block object res = NSOCR.Engine.Blk_GetType(BlkObj); //get zone type NSOCR.Engine.Blk_GetRect(BlkObj, Xpos, Ypos, Width, Height); //get zone position and size res = NSOCR.Engine.Blk_Inversion(BlkObj, NSOCR.Constant.BLK_INVERSE_GET); //get zone inversion res = NSOCR.Engine.Blk_Rotation(BlkObj, NSOCR.Constant.BLK_ROTATE_GET); //get zone rotation res = NSOCR.Engine.Blk_Mirror(BlkObj, NSOCR.Constant.BLK_MIRROR_GET); //get zone mirror flag res = NSOCR.Engine.Blk_GetBackgroundColor(BlkObj); //get zone background color NSOCR.Engine.Blk_GetText(BlkObj, txt, NSOCR.Constant.FMT_EDITCOPY); //get zone text System.out.println(txt); lcnt = NSOCR.Engine.Blk_GetLineCnt(BlkObj); //get number of text lines for zone for (j = 0; j < lcnt; j++) { NSOCR.Engine.Blk_GetTextRect(BlkObj, j, -1, Xpos, Ypos, Width, Height); //get text line position and size NSOCR.Engine.Blk_GetLineText(BlkObj, j, txt); //get line text System.out.println(txt); wcnt = NSOCR.Engine.Blk_GetWordCnt(BlkObj, j); //get number of words of "j"-th text line of zone for (k = 0; k < wcnt; k++) { NSOCR.Engine.Blk_GetTextRect(BlkObj, j, k, Xpos, Ypos, Width, Height); //get word position and size res = NSOCR.Engine.Blk_GetWordFontColor(BlkObj, j, k); //get word font color res = NSOCR.Engine.Blk_GetWordFontSize(BlkObj, j, k); //get word font size res = NSOCR.Engine.Blk_GetWordFontStyle(BlkObj, j, k); //get word font style res = NSOCR.Engine.Blk_GetWordQual(BlkObj, j, k); //get word quality res = NSOCR.Engine.Blk_IsWordInDictionary(BlkObj, j, k); //check if this word is in dictionary NSOCR.Engine.Blk_GetWordText(BlkObj, j, k, txt); //get word text System.out.println(txt); } } } NSOCR.Engine.Engine_Uninitialize(); //release all created objects and uninitialize OCR engine