Files
OCR_Decode/OCR_Decode/DriverNameWindow.cs
T

43 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tesseract;
namespace OCR_Decode
{
internal class DriverNameWindow : Window
{
public static Random rnd = new Random();
public DriverNameWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
{
Name = "Name";
}
public override object DecodePng(List<string> DriverList)
{
string result = "";
result = GetStringFromPng();
if (!IsADriver(DriverList, result))
{
//I put everything in uppercase to try to lower the chances of bad answers
result = FindClosestMatch(DriverList.ConvertAll(d => d.ToUpper()), result.ToUpper());
}
return result;
}
private static bool IsADriver(List<string> drivers, string potentialDriver)
{
bool result = false;
//I cant use drivers.Contains because it has missmatched cases and all
foreach (string name in drivers)
{
if (name.ToUpper() == potentialDriver.ToUpper())
result = true;
}
return result;
}
}
}