Aspose OCR on BMP Images

Hi


I am trying to use Aspose OCR inorder to extract text form image .
I get following exception when I I try to extract image .
Here is my code :

OcrEngine ocrEngine = new OcrEngine();
ocrEngine.Image = ImageStream.FromFile(@“C:\Generator\test1.bmp”);

//add language and other attributes
ocrEngine.Languages.AddLanguage(Language.Load(“English”));
ocrEngine.Config.NeedRotationCorrection = false;
ocrEngine.Config.UseDefaultDictionaries = true;
//load the resource file
ocrEngine.Resource = new FileStream(@“C:\Aspose Purchased lic\Aspose.OCR.1.8.0.Resouces.zip”, FileMode.Open);
//process the whole image
try
{
if (ocrEngine.Process())
{
Console.WriteLine(“Text :{0}”, ocrEngine.Text);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}


Hi Kathleen,

Thank you for contacting support, and we are sorry for your inconvenience.

Your source code seems to be correct and it shouldn’t throw an exception if you are using the latest version of Aspose.OCR for .NET 1.8.0 (as your resource file name suggests). Please provide the error details along with the sample image that is triggering the exception so we could analyze it on our end to provide further assistance in this regard.

Looking forward to your response.

Hi Babar



Thanks for your quick response . Here are the details of the Error and The test images which I am using .



Hi Kathleen,

Thank you for sharing the sample images.

Unfortunately, we are unable to observe any exception while performing OCR operation on your provided sample while using Aspose.OCR for .NET 1.8.0. The sample test1.bmp returned the perfect results, whereas test2.bmp returned garbage data. Most probable reason for incorrect recognized text for test2.bmp is the font size of the text. Please note, current implementation of Aspose.OCR for .NET API has 90% and more reliability rate with font size 30pts, and reliability decreases with small font sizes. We are working hard on new algortithms for OcrEngine, that upon implementation will yield better results in terms of reliability and performance.

By checking the error message in your provided screenshot, we suspect that you are using an older version of the API. Could you please double check this on your end? In case the problem persists please provide a runnable sample project to reproduce the said exception on our end.

Test code is provided below for reference,
C#


// image document on which OCR is to be performed
string imageFile = (MyDir + “test2.bmp”);

// Initialize OcrEngine
OcrEngine ocr = new OcrEngine();
ocr.Config.NeedRotationCorrection = false;
ocr.Config.UseDefaultDictionaries = true;

// Load Image
ocr.Image = ImageStream.FromFile(imageFile);

// Add language
ocr.Languages.AddLanguage(Language.Load(“english”));

// Output file to store results
TextWriter outPut = new StreamWriter(MyDir+“output.txt”);

// Load the resource file
using (ocr.Resource = new FileStream(resourceFileName, FileMode.Open))
{
try
{
// Process the whole image
if (ocr.Process())
{
outPut.WriteLine(ocr.Text);
Console.WriteLine(ocr.Text);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
outPut.Close();

}

Hi Babar



Thanks for the information . I was using v1.6 dll . I have updated the dll and test1.bmp works fine now .
Thank you .



Hi again,

Thank you for the confirmation on this. Please note, each version of Aspose.OCR for .NET API uses a specific resource file. If you try to use the resource file from any other version of the API then you may experience exception or undesired results. Therefore it is suggested that you should always update resource file when upgrading the API.

Please feel free to write back any time.