Nicomsoft OCR: Developer's Guide |
C++: | int Blk_GetBarcodeCnt(HBLK BlkObj) |
C#: | int Blk_GetBarcodeCnt(int BlkObj) |
Visual Basic: | Function Blk_GetBarcodeCnt(ByVal BlkObj As Integer) As Integer |
Java: | int Blk_GetBarcodeCnt(HBLK BlkObj) |
Delphi: | function Blk_GetBarcodeCnt(BlkObj:HBLK):integer |
BlkObj [IN] – the Block object. You can also specify the Image object if you want to work with the global list of barcodes for the entire image. |
int CfgObj, OcrObj, ImgObj, res, cnt, i, n, Xpos, Ypos, Width, Height; wchar_t* txt; Engine_InitializeAdvanced(&CfgObj, &OcrObj, &ImgObj); //initialize OCR engine, create objects and load configuration Cfg_SetOption(CfgObj, BT_DEFAULT, L"Zoning/FindBarcodes", L"2"); //recognize barcodes only //note: it is also possible to disable rescaling, deskew etc. to achieve best performance, check "Performace Tips" section 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 cnt = Blk_GetBarcodeCnt(ImgObj); //get number of barcodes of entire image for (i = 0; i < cnt; i++) { Blk_GetBarcodeRect(ImgObj, i, &Xpos, &Ypos, &Width, &Height); //get barcode position and size res = Blk_GetBarcodeType(ImgObj, i); //get barcode type n = Blk_GetBarcodeText(ImgObj, i, NULL, 0) + 1; //get buffer size plus terminating NULL character txt = (wchar_t*) malloc(sizeof(wchar_t) * n); //allocate memory for text Blk_GetBarcodeText(ImgObj, i, txt, n); //get barcode 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, res, cnt, i, 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 NsOCR.Cfg_SetOption(CfgObj, TNSOCR.BT_DEFAULT, "Zoning/FindBarcodes", "2"); //recognize barcodes only 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 cnt = NsOCR.Blk_GetBarcodeCnt(ImgObj); //get number of barcodes of entire image for (i = 0; i < cnt; i++) { NsOCR.Blk_GetBarcodeRect(ImgObj, i, out Xpos, out Ypos, out Width, out Height); //get barcode position and size res = NsOCR.Blk_GetBarcodeType(ImgObj, i); //get barcode type NsOCR.Blk_GetBarcodeText(ImgObj, i, out txt); //get barcode 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, res, cnt, i, 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 NsOCR.Cfg_SetOption(CfgObj, TNSOCR.BT_DEFAULT, "Zoning/FindBarcodes", "2") 'recognize barcodes only 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 cnt = NsOCR.Blk_GetBarcodeCnt(ImgObj) 'get number of barcodes of entire image For i = 0 To cnt - 1 NsOCR.Blk_GetBarcodeRect(ImgObj, i, Xpos, Ypos, Width, Height) 'get barcode position and size res = NsOCR.Blk_GetBarcodeType(ImgObj, i) 'get barcode type NsOCR.Blk_GetBarcodeText(ImgObj, i, txt) 'get barcode text 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(); int res, cnt, i; NSOCR.NSInt Xpos, Ypos, Width, Height; Xpos = new NSOCR.NSInt(0); Ypos = new NSOCR.NSInt(0); Width = new NSOCR.NSInt(0); Height = new NSOCR.NSInt(0); StringBuffer txt = new StringBuffer(); NSOCR.Engine.Engine_InitializeAdvanced(CfgObj, OcrObj, ImgObj); //initialize OCR engine, create objects and load configuration NSOCR.Engine.Cfg_SetOption(CfgObj, NSOCR.Constant.BT_DEFAULT, "Zoning/FindBarcodes", "2"); //recognize barcodes only 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 OCR if (res > NSOCR.Error.ERROR_FIRST) {}; //insert error handler here NSOCR.HBLK BlkObj = new NSOCR.HBLK(); //create temporary BLK object because we cannot pass ImgObj to Blk_GetBarcodeCnt directly BlkObj.SetValue(ImgObj.GetValue()); //it is just a copy of ImgObj cnt = NSOCR.Engine.Blk_GetBarcodeCnt(BlkObj); //get number of barcodes of entire image for (i = 0; i < cnt; i++) { NSOCR.Engine.Blk_GetBarcodeRect(BlkObj, i, Xpos, Ypos, Width, Height); //get barcode position and size res = NSOCR.Engine.Blk_GetBarcodeType(BlkObj, i); //get barcode type NSOCR.Engine.Blk_GetBarcodeText(BlkObj, i, txt); //get barcode text System.out.println(txt.toString()); } NSOCR.Engine.Engine_Uninitialize(); //release all created objects and uninitialize OCR engine