Hi Team,
I have to parse the attached .png image using OCR Engine and i should get the TAN number from it.
Kindly help me on this.
Hi Naveen,
Thank you for considering Aspose APIs.
I have checked your sample, and I regret to inform you that Aspose.OCR for .NET API is not able to recognize the TAN number from your provided sample due to the low resolution. Please note, the recommended resolution of optimal accuracy is 300DPI whereas your provided sample has 120DPI.
Please provide a high resolution image by scanning the document at 300DPI. Moreover, you can use the following piece of code to recognize only the TAN number. I have also included the code snippet to save the preprocessed images just to be sure that the provided location for the TAN number is correct.
C#
string imageFile = “D:/tax.png”;
//Initialize an instance of OcrEngine
OcrEngine ocrEngine = new OcrEngine();
//Clear notifier list
ocrEngine.ClearNotifies();
//Clear recognition blocks
ocrEngine.Config.ClearRecognitionBlocks();
//Add 1 rectangle to user defined recognition block
//Please change the location & dimensions according to the new image
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(36, 105, 70, 11)); //Detecting TAN
//Ignore everything else on the image other than the user defined recognition blocks
ocrEngine.Config.DetectTextRegions = false;
//Set Image property by loading an image from file path
ocrEngine.Image = ImageStream.FromFile(imageFile);
//Run recognition process
if (ocrEngine.Process())
{
//Save binarized image on disc
ocrEngine.PreprocessedImages.BinarizedImage.Save(@“D:\BinarizedImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save filtered image on disc
ocrEngine.PreprocessedImages.FilteredImage.Save(@“D:\FilteredImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save image after removing non-textual fragments
ocrEngine.PreprocessedImages.NonTextRemovedImage.Save(@“D:\NonTextRemovedImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save image after skew correction
ocrEngine.PreprocessedImages.RotatedImage.Save(@“D:\RotatedImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save image after textual block detection
ocrEngine.PreprocessedImages.TextBlocksImage.Save(@“D:\TextBlocksImage.png”, System.Drawing.Imaging.ImageFormat.Png);
Console.WriteLine(ocrEngine.Text);
}
//Initialize an instance of OcrEngine
OcrEngine ocrEngine = new OcrEngine();
//Clear notifier list
ocrEngine.ClearNotifies();
//Clear recognition blocks
ocrEngine.Config.ClearRecognitionBlocks();
//Add 1 rectangle to user defined recognition block
//Please change the location & dimensions according to the new image
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(36, 105, 70, 11)); //Detecting TAN
//Ignore everything else on the image other than the user defined recognition blocks
ocrEngine.Config.DetectTextRegions = false;
//Set Image property by loading an image from file path
ocrEngine.Image = ImageStream.FromFile(imageFile);
//Run recognition process
if (ocrEngine.Process())
{
//Save binarized image on disc
ocrEngine.PreprocessedImages.BinarizedImage.Save(@“D:\BinarizedImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save filtered image on disc
ocrEngine.PreprocessedImages.FilteredImage.Save(@“D:\FilteredImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save image after removing non-textual fragments
ocrEngine.PreprocessedImages.NonTextRemovedImage.Save(@“D:\NonTextRemovedImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save image after skew correction
ocrEngine.PreprocessedImages.RotatedImage.Save(@“D:\RotatedImage.png”, System.Drawing.Imaging.ImageFormat.Png);
//Save image after textual block detection
ocrEngine.PreprocessedImages.TextBlocksImage.Save(@“D:\TextBlocksImage.png”, System.Drawing.Imaging.ImageFormat.Png);
Console.WriteLine(ocrEngine.Text);
}
Hi Team,
I am very happy with your quick response on my post.
I would like to know more about the line:
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(36, 105, 70, 11)); //Detecting TAN
How can i know the X-cordinate,Y-Cordinate,Width and Height of the specific block by looking at the image??
Help me to get the TAN number from the attached image from this post?
Hi Naveen,
Thank you for your valuable feedback.
There are different software that provides the information about the X, Y Coordinates, Width and Height of the area selected on the image. Microsoft Paint and TechSmith Snagit are the examples. If you consider MS Paint, open the image in MS Paint and pick the Selection Tool from Home tab on the top. This tool will help you to select the part of the image. While using Selection Tool, look at the left down corner on the Status Bar. You will be able to find the X, Y Coordinates and Width, Height of the selected area on the image.
Moreover, this feature would be applicable when the scanned sheets (the image) follows the same structure, means the TAN number would always be on same location on each scanned sheets (on same coordinates). If you want to process scanned sheets having different structure then you have to define the X, Y Coordinates and Width, Height according to the scanned sheets or you have to perform OCR on the complete image and extract the required information from the text recognized by the OCR Engine.
For the attached image, you can use the following line of code:
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(306, 553, 235, 33)); //Detecting TAN