Nicomsoft OCR: Developer's Guide


Img_GetPixLineCnt


Syntax

C++:int Img_GetPixLineCnt(HIMG ImgObj)
C#:int Img_GetPixLineCnt(int ImgObj)
Visual Basic:Function Img_GetPixLineCnt(ByVal ImgObj As Integer) As Integer
Java:int Img_GetPixLineCnt(HIMG ImgObj)
Delphi:function Img_GetPixLineCnt(ImgObj:HIMG):integer;


Description

Retrieves the number of detected and removed lines in the image. The "lines" are table frames, frames around text, and so on.


Parameters

ImgObj [IN] – the Image object.


Return value

If success, the number of lines; otherwise, an error code.


Remarks

The lines removal algorithm is applied at the OCRSTEP_REMOVELINES step, so this step must be executed before calling this function.


Example

The following sample loads an image and executes several OCR steps to find pixel lines and other properties of the final image before text recognition:

C++
int CfgObj, OcrObj, ImgObj, res, cnt, i, X1pos, Y1pos, X2pos, Y2pos, Width;
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_GetProperty(ImgObj, IMG_PROP_DPIX); //get image DPI stored in image file (if available)
res = Img_OCR(ImgObj, OCRSTEP_FIRST, OCRSTEP_REMOVELINES, OCRFLAG_NONE); //perform OCRSTEP_FIRST...OCRSTEP_REMOVELINES OCR steps
if (res > ERROR_FIRST) {}; //insert error handler here
res = Img_GetScaleFactor(ImgObj); //at OCRSTEP_PREFILTERS image can be resized, get scale factor
res = Img_GetSkewAngle(ImgObj); //at OCRSTEP_PREFILTERS image can be deskewed, get skew angle
cnt = Img_GetPixLineCnt(ImgObj); //get number of lines
for (i = 0; i < cnt; i++)
{
  Img_GetPixLine(ImgObj, i, &X1pos, &Y1pos, &X2pos, &Y2pos, &Width); //get line properties
}
//res = Img_OCR(ImgObj, OCRSTEP_REMOVELINES + 1, OCRSTEP_LAST, OCRFLAG_NONE); //perform rest of OCR steps if necessary
Engine_Uninitialize(); //release all created objects and uninitialize OCR engine


C#
//assume reference to NSOCR COM was added
using NSOCR_NameSpace; //Add NSOCR namespace from "NSOCR.cs" file
//...
int CfgObj, OcrObj, ImgObj, res, cnt, i, X1pos, Y1pos, X2pos, Y2pos, Width;
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_GetProperty(ImgObj, TNSOCR.IMG_PROP_DPIX); //get image DPI stored in image file (if available)
res = NsOCR.Img_OCR(ImgObj, TNSOCR.OCRSTEP_FIRST, TNSOCR.OCRSTEP_REMOVELINES, TNSOCR.OCRFLAG_NONE); //perform OCRSTEP_FIRST...OCRSTEP_REMOVELINES OCR steps
if (res > TNSOCR.ERROR_FIRST) {}; //insert error handler here
res = NsOCR.Img_GetScaleFactor(ImgObj); //at OCRSTEP_PREFILTERS image can be resized, get scale factor
res = NsOCR.Img_GetSkewAngle(ImgObj); //at OCRSTEP_PREFILTERS image can be deskewed, get skew angle
cnt = NsOCR.Img_GetPixLineCnt(ImgObj); //get number of lines
for (i = 0; i < cnt; i++)
{
  NsOCR.Img_GetPixLine(ImgObj, i, out X1pos, out Y1pos, out X2pos, out Y2pos, out Width); //get line properties
}
//res = NsOCR.Img_OCR(ImgObj, TNSOCR.OCRSTEP_REMOVELINES + 1, TNSOCR.OCRSTEP_LAST, TNSOCR.OCRFLAG_NONE); //perform rest of OCR steps if necessary
NsOCR.Engine_Uninitialize(); //release all created objects and uninitialize OCR engine


VB.NET
'assume reference to NSOCR COM was added
'assume "NSOCR.vb" file was added to project
Dim CfgObj, OcrObj, ImgObj, res, cnt, i, X1pos, Y1pos, X2pos, Y2pos, Width As Integer
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_GetProperty(ImgObj, TNSOCR.IMG_PROP_DPIX) 'get image DPI stored in image file (if available)
res = NsOCR.Img_OCR(ImgObj, TNSOCR.OCRSTEP_FIRST, TNSOCR.OCRSTEP_REMOVELINES, TNSOCR.OCRFLAG_NONE) 'perform OCRSTEP_FIRST...OCRSTEP_REMOVELINES OCR steps
If res > TNSOCR.ERROR_FIRST Then 'insert error handler here
End If
res = NsOCR.Img_GetScaleFactor(ImgObj) 'at OCRSTEP_PREFILTERS image can be resized, get scale factor
res = NsOCR.Img_GetSkewAngle(ImgObj) 'at OCRSTEP_PREFILTERS image can be deskewed, get skew angle
cnt = NsOCR.Img_GetPixLineCnt(ImgObj) 'get number of lines
For i = 0 To cnt - 1
  NsOCR.Img_GetPixLine(ImgObj, i, X1pos, Y1pos, X2pos, Y2pos, Width) 'get line properties
Next i
'res = NsOCR.Img_OCR(ImgObj, TNSOCR.OCRSTEP_REMOVELINES + 1, TNSOCR.OCRSTEP_LAST, TNSOCR.OCRFLAG_NONE) 'perform rest of OCR steps if necessary
NsOCR.Engine_Uninitialize() 'release all created objects and uninitialize OCR engine


Java
//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, i, cnt;
NSOCR.NSInt X1pos = new NSOCR.NSInt(0);
NSOCR.NSInt Y1pos = new NSOCR.NSInt(0);
NSOCR.NSInt X2pos = new NSOCR.NSInt(0);
NSOCR.NSInt Y2pos = new NSOCR.NSInt(0);
NSOCR.NSInt Width = new NSOCR.NSInt(0);
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_GetProperty(ImgObj, NSOCR.Constant.IMG_PROP_DPIX); //get image DPI stored in image file (if available)
res = NSOCR.Engine.Img_OCR(ImgObj, NSOCR.Constant.OCRSTEP_FIRST, NSOCR.Constant.OCRSTEP_REMOVELINES, NSOCR.Constant.OCRFLAG_NONE); //perform OCRSTEP_FIRST...OCRSTEP_REMOVELINES OCR steps
if (res > NSOCR.Error.ERROR_FIRST) {}; //insert error handler here
res = NSOCR.Engine.Img_GetScaleFactor(ImgObj); //at OCRSTEP_PREFILTERS image can be resized, get scale factor
res = NSOCR.Engine.Img_GetSkewAngle(ImgObj); //at OCRSTEP_PREFILTERS image can be deskewed, get skew angle
cnt = NSOCR.Engine.Img_GetPixLineCnt(ImgObj); //get number of lines
for (i = 0; i < cnt; i++)
{
  NSOCR.Engine.Img_GetPixLine(ImgObj, i, X1pos, Y1pos, X2pos, Y2pos, Width); //get line properties
  System.out.println(X1pos.GetValue() + " " + Y1pos.GetValue() + " " + X2pos.GetValue() + " " + Y2pos.GetValue() + " " + Width.GetValue());
}
//res = NSOCR.Engine.Img_OCR(ImgObj, NSOCR.Constant.OCRSTEP_REMOVELINES + 1, NSOCR.Constant.OCRSTEP_LAST, NSOCR.Constant.OCRFLAG_NONE); //perform rest of OCR steps if necessary
NSOCR.Engine.Engine_Uninitialize(); //release all created objects and uninitialize OCR engine