Aspose OCR Example - OCRException - invalid version of serialzed data

Hi,

I downloaded and installed the Aspose.Totals for .NET, and installed the Aspose Examples Dashboard. However, when I try to run the Aspose.OCR example via the dashboard I get an exception; if I try to open the solution via the dashboard, Visual Studio 2010 simply says the project has been unloaded.

Could someone please help? I’m trying to evaluate the software to see if it meets our needs for a project, but can not do so without being able to run the examples.

Here is the exception message from the dashboard after I click ‘Run Example’:
Running example…
Performing OCR on Sampleocr.bmp…
Exception: Aspose.OCR.OcrException: Error occurred during recognition. —> System.Exception: Error while loading 0 net (Network_12netsFS_Arial_BigAlphabet_18x18_8pt_468-26_v4L): Invalid version of serialized data —> System.InvalidOperationException: Invalid version of serialized data
at ..(BinaryReader )
at ..T
at ..(Stream )
at .…ctor( , ILanguage , String[] , String[] , String[] )
— End of inner exception stack trace —
at .…ctor( , ILanguage , String[] , String[] , String[] )
at .a.( , ILanguage )
at .…ctor( , ILanguage )
at ..( , ILanguage )
at Aspose.OCR.OcrEngine.()
— End of inner exception stack trace —
at Aspose.OCR.OcrEngine.()
at PerformOCROnImage.Program.Main(String[] args) in C:\Users\acwhitfield\Documents\Aspose\Aspose.OCR for .NET\Examples\ProgrammersGuide\WorkingWithOCR\PerformOCROnImage\VisualBasic\Program.vb:line 35
Completed successfully.

Hi Amy,

We are sorry for your inconvenience.

As per the exception message, it seems that the example dashboard application didn’t download the Resource files, or the downloaded file is corrupt. I have logged a ticket (SUPPORT-2876) in this regard. We will soon check and fix the example dashboard for Aspose.OCR product samples.

Please note, you have to set the Resource file in your source code before calling the OcrEngine.Process method. Moreover, each release of Aspose.OCR for .NET has a specified Resource file. In case the Resource file set in source code is not for the specified version of Aspose.OCR component then you may get similar exception.

I have created a sample application (C# Visual Studio 2010) so you could test the product functionality on your end. Latest assembly for Aspose.OCR for .NET v1.7.0 is included in the project archive along with a sample image for your reference, but you have to download the Resource file from here.

Please feel free to write back if you have more questions.

Hi Babar,


Thank you for your response, and providing the sample application! Unfortunately, I’m not able to load the sample application in Visual Studio 2010. When I attempt to open the solution, Visual Studio 2010 says the SimpleTestOcrApp is unavailable and that the project file was unloaded.

I have downloaded the resource zip file, but without being able to load the project I can’t even get to the point of setting the resource file in the source code.

I do have Visual Studio 2012 also installed on my machine, but I don’t think that should be causing any issues. Any ideas why the sample project won’t load?

Thanks!

Hi Amy,

I am sorry to know that you are still facing issues.

The project I have shared in my last reply is working fine on my end. I have also tried the project/solution download by Aspose Examples Dashboard, they are working fine as well. I have no idea why you are unable to load these project. This couldn’t be due to the reason that you have multiple Visual Studio versions installed on your machine, because I have Visual Studio 2010, 2012 and 2013 at the same time.

You can create a new project of your own, all you need is the source code for performing OCR operation on an image. Please check the below provided code snippet, and change the file location paths as per your system.

C#


// Initialize OcrEngine
var ocr = new Aspose.OCR.OcrEngine();

// Configure to use Default Dictionaries
ocr.Config.UseDefaultDictionaries = true;

// Load Image by passing the image file location path
ocr.Image = Aspose.OCR.ImageStream.FromFile(imagePath);

// Add language; you can add multiple languages
ocr.Languages.AddLanguage(Aspose.OCR.Language.Load(“english”));

// OutPut file to store results; initialize the StreamWriter with file location path
TextWriter outPut = new StreamWriter(outputPath);

// Load the resource file through FileStream by passing the Resource file location path
using (ocr.Resource = new FileStream(resourcesPath, FileMode.Open))
{
try
{
// Process the whole image
if (ocr.Process())
{
// Write results to output
outPut.WriteLine(ocr.Text);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
outPut.Close();
}

Please note, you have to update the file location paths for the following variables as highlighted in above code snippet,
  1. imagePath: Image to be loaded
  2. resourcesPath: Resource file
  3. outputPath: Output file for results.

Hope this helps a bit. Please keep us posted with you feedback.

Hi,


It appears something is wrong with Visual Studio 2010 on my machine. I opened the project you provided in Visual Studio 2012 and was able to get the project to run without any problems.

Regarding the Aspose Examples Dashboard, I still get the exception error when trying to run the Aspose.OCR example. You mentioned this was likely due to not being able to find the Resource file?

The path in the exception message is:
C:\Users\acwhitfield\Documents\Aspose\Aspose.OCR for .NET\Examples\ProgrammersGuide\WorkingWithOCR\PerformOCROnImage\VisualBasic\Program.vb:line 35

The Resource file that was installed along with the Dashboard is located in:
C:\Users\acwhitfield\Documents\Aspose

Did I perhaps do something incorrectly when installing the Dashboard and examples?

Thank you for all your help!

Hi Amy,

Just to let you know that we have fixed the issue in Aspose Examples Dashboard for the exception message mentioned in your original post. Please delete the bin & resources folder under Aspose.OCR for .NET root folder and run the Aspose Examples Dashboard to download the deleted files once again.

Alternatively, you can also rename your previously downloaded resource file (should be of size 89,913 KB) to “aspose.ocr.resources.zip” and place it in …\Aspose\Aspose.OCR for .NET\resources folder before restarting the Aspose Examples Dashboard.

Please feed us back with your results on this.

Hi again,

Sorry, I didn’t see your response before posting this message. As shared earlier, the problem in Aspose Examples Dashboard has been fixed from our end. All you have to do is to delete the following two folders, and run the Dashboard. It will detect the deleted folders/files so they will be downloaded again.

  1. C:\Users\acwhitfield\Documents\Aspose\Aspose.OCR for .NET\resources
  2. C:\Users\acwhitfield\Documents\Aspose\Aspose.OCR for .NET\bin

Please note, the problem was due to the incorrect version of resource archive. If you have already downloaded the resource file from this link, you may simply rename the file to “aspose.ocr.resources.zip” and place it in “C:\Users\acwhitfield\Documents\Aspose\Aspose.OCR for .NET\resources” folder to make the Aspose.OCR for .NET examples run fine.

Please let us know if you still find any issue or need further help.

Hi,


Deleting the bin and resource folders did the trick. :slight_smile: The example ran successfully; however, I did have a question about the resulting text file.

I noticed the sample image contains the alphabet in lower case, upper case, the numbers 0 through 9, and some punctuation. The output text file contained only the alphabet in lower and upper case. Should the numbers 0 through 9 and the punctuation have been included in the output file?

I’ve attached a screenshot for reference which includes the Output in the dashboard, the Sampleocr.bmp, and the Output.txt file.

Thank you!

Hi Amy,

First of all, please accept my apology for a bit delayed response.

I have noticed the same issue on my end as well. Although the image contains a-z, A-Z, 0-9 and a few symbols, but when we read this using Aspose.OCR for .NET v1.7.0, the result contains only a-z & A-W. Rest of the text is getting missed from the recognition process.

I am currently working on this issue, and I will soon get back to you with more updates in this regard.

Hi Amy,

Just to inform you that the behaviour of Aspose.OCR for .NET component as stated here has been logged in our bug tracking system for further investigation and correction. The ticket Id for future reference is OCR-33601. We are currently looking into this matter on priority basis, and we hope to provide a fix or any workaround at earliest.

Please accept our apologies for your inconvenience.

Hi Amy,

Sorry for the confusion.

The behavior of Aspose.OCR for .NET presented here is actually the evaluation limitation of Aspose.OCR component. Aspose Examples Dashboard and the project shared by me both lacks the licensing statements that is why the resultant recognized text is incomplete as compared to the text in the sample image. If you set a valid license before making any calls to Aspose.OCR for .NET API, you will get the complete text including the numbers and punctuation.

If you want to test Aspose.OCR for .NET component in its full capacity, I would recommend you to get a 30 days trial license by following the instructions provided on below link.
http://www.aspose.com/wiki/default.aspx/Aspose.Corporate/HowToGetTemporaryLicense.html

As soon as you get the license file, you just have to add the following two lines of code in your test project in order to make your copy of the component licensed. For reference please also check the below linked technical article on this subject.
http://www.aspose.com/docs/display/ocrnet/Licensing

C#


//Initialize an instance of Aspose.OCR.License class to call SetLicense Method
Aspose.OCR.License license = new Aspose.OCR.License();

//Please specify the full path to your license file in SetLicense Method
license.SetLicense(“Aspose.Total.Product.Family.lic”);


Please let us know if you need further guidance or have any questions.

Hi Babar,


Thank you for all your time and help with this! I apologize if I overlooked information stating the trial version would not generate the full sample image. :slight_smile:

I did follow the steps for the 30 day evaluation trial license. I added the two lines of code, and set the path to the evaluation license, and the full text was generated in the output file.

On a related side note, I do have some questions about working with the OMR Template Editor, but will post those in a separate forum entry since the questions aren’t related to the OCR example and I don’t want to confuse things.

Thank you again for all your help!
Amy

Hi Amy,

Thank you for your feedback.

It is good to know that you are up and running again. Please create separate forum threads for every individual issue that you encounter. It is the best approach as it minimizes the confusion and keeps the issue tracking very easy.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.