Trying to implement tyres but not working for now

This commit is contained in:
2023-04-07 15:58:12 +02:00
parent b43b61d9b0
commit 124d141181
6 changed files with 187 additions and 72 deletions
+12 -14
View File
@@ -153,22 +153,14 @@ namespace OCR_Decode
page.Dispose();
return result;
}
protected string GetStringFromPng(bool onlyDigit = false)
public static string GetStringFromPng(Bitmap image,string allowedChars = "",OcrImage.WindowType windowType = OcrImage.WindowType.Text)
{
string result = "";
if (onlyDigit)
{
Engine.SetVariable("tessedit_char_whitelist", "0123456789");
}
else
{
Engine.SetVariable("tessedit_char_whitelist", "");
}
Engine.SetVariable("tessedit_char_whitelist", allowedChars);
Bitmap rawData = WindowImage;
Bitmap enhancedImage = new OcrImage(rawData).Enhance();
Bitmap rawData = image;
Bitmap enhancedImage = new OcrImage(rawData).Enhance(windowType);
Page page = Engine.Process(enhancedImage);
using (var iter = page.GetIterator())
@@ -185,7 +177,13 @@ namespace OCR_Decode
page.Dispose();
return result;
}
//This method has been gnerated using ChatGPT
protected Bitmap GetSmallBitmapFromBigOne(Bitmap bmp, Rectangle rectangle)
{
Bitmap sample = new Bitmap(rectangle.Width, rectangle.Height);
Graphics g = Graphics.FromImage(sample);
g.DrawImage(bmp, new Rectangle(0, 0, sample.Width, sample.Height), rectangle, GraphicsUnit.Pixel);
return sample;
}
protected static string FindClosestMatch(List<string> array, string target)
{
var closestMatch = "";
@@ -202,7 +200,7 @@ namespace OCR_Decode
}
return closestMatch;
}
//This is a tool to be able to compare strings
//This method has been generated with the help of ChatGPT
protected static int LevenshteinDistance(string s1, string s2)
{
if (string.IsNullOrEmpty(s1))