I need to extract the kilogram (kg) values displayed in the image below:
I manually cropped the image to isolate the text part and applied several image processing techniques such as grayscale conversion, thresholding, Gaussian blur, and dilation. However, the results were not as clear as I expected, and Tesseract OCR was unable to read them. Here are some of the processed images:
I am currently using EmguCV and Tesseract, and have tried various tesseract models including tessdata_best
(English), lets
, and letsgodigital
. Unfortunately, none of these attempts have been successful.
The specific language or library used is not crucial, as I plan to convert the solution to C#. The final implementation will be for a mobile app using Xamarin.Forms.
Below is a sample method that I used without success:
public static void Apply()
{
var folderName = "letsgodigital";
var dataname = "letsgodigital";
string tesseractPath = @$"./{folderName}";
string imagePath = @"img.jpg";
Mat image = CvInvoke.Imread(imagePath, ImreadModes.Color);
Mat blurredImg = new Mat();
CvInvoke.Blur(image, blurredImg, new Size(9, 9), new Point(-1, -1));
Mat grayImg = new Mat();
CvInvoke.CvtColor(blurredImg, grayImg, ColorConversion.Bgr2Gray);
Mat binaryImg = new Mat();
CvInvoke.Threshold(grayImg, binaryImg, 122, 255, ThresholdType.Binary);
binaryImg.Save("full_pannel_bw.png");
using (var engine = new TesseractEngine(tesseractPath, dataname, EngineMode.Default))
{
engine.DefaultPageSegMode = PageSegMode.SingleLine;
using (var img = Pix.LoadFromFile("full_pannel_bw.png"))
{
using (var page = engine.Process(img))
{
string text = page.GetText();
Console.WriteLine("tesseract got: "{0}"", text.Trim());
}
}
}
}