Hello Aspose team,
I’ve been trying to implement Aspose OCR with the multilanguage functionality into my workflow, but have hit a bit of a roadblock.
When attempting to OCR specifically the following image:
i600_comp_superior_1.jpg (182.9 KB)
I run into a System.NullReferenceException with the following stacktrace:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at .(Byte[,][] , InferenceSession, Boolean )
at .(List`1 , InferenceSession)
at.(List`1 , RecognitionSettings, ␦ )
at.(RecognitionSettings , ␦)
at.(RecognitionSettings , ␦)
at Aspose.OCR.AsposeOcr.(Bitmap& , String, RecognitionSettings , ␦ )
at .(ImageData , RecognitionSettings, ␦ , )
at .(ImageData , RecognitionSettings, ␦ , )
at .(OcrInput , RecognitionSettings, ␦ , , CancellationToken )
at .(OcrInput , RecognitionSettings, ␦ , )
at Aspose.OCR.AsposeOcr.Recognize(OcrInput images, RecognitionSettings settings)
at AsposeOcrSavePdfIssue.Program.Main(String[] args) in C:\Users\user\source\repos\AsposeOcrSavePdfIssue\AsposeOcrSavePdfIssue\Program.cs:line 19
I have written a simple .NET Framework 4.8 console application which attempts to load in the file and perform OCR using RecognitionSettings(language: Language.Multilanguage) as seen below:
using System.IO;
using Aspose.OCR;
namespace AsposeOcrMultiLanguage
{
internal class Program
{
static void Main(string[] args)
{
var license = new Aspose.OCR.License();
var ms = new MemoryStream(Properties.Resources.Aspose_Total_NET);
license.SetLicense(ms);
var path = @"i600_comp_superior_1.jpg";
var stream = OpenImageIntoMemoryStream(path);
OcrInput input = new OcrInput(InputType.SingleImage);
RecognitionSettings recognitionSettings = new RecognitionSettings(language: Language.Multilanguage);
AsposeOcr recognitionEngine = new AsposeOcr();
input.Add(stream);
var results = recognitionEngine.Recognize(input, recognitionSettings);
AsposeOcr.SaveMultipageDocument(fullFileName: "./test_i600_comp_superior_1.pdf", saveFormat: SaveFormat.Pdf, results: results, optimizePdf: PdfOptimizationMode.NONE);
}
public static MemoryStream OpenImageIntoMemoryStream(string path)
{
byte[] fileBytes = File.ReadAllBytes(path);
MemoryStream memoryStream = new MemoryStream(fileBytes);
return memoryStream;
}
}
}
Please note that I have not attached the license file. In the example above it is attached as a resource to the project, referenced as Properties.Resources.
The input image can be specified, but defaults to the source location of the executable.
It’s also important to note that if using a different language, e.g. setting RecognitionSettings(language: Language.Eng), the exception does not occur. This makes me think it is unique to the multi-language functionality.
Finally, I attempted to OCR a merged TIFF image which contains the problem image and setting OcrInput(InputType.TIFF). This also caused the same exception.