Added DRS recognition

This commit is contained in:
2023-04-06 13:18:47 +02:00
parent 308ef06a6d
commit 2bbe831546
4 changed files with 98 additions and 4 deletions
+92 -2
View File
@@ -4,19 +4,109 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tesseract;
using System.Windows.Forms;
namespace OCR_Decode
{
internal class DriverDrsWindow : Window
{
private static int EmptyDrsGreenValue = -1;
private static Random rnd = new Random();
public DriverDrsWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
{
Name = "DRS";
}
public override object DecodePng()
{
//TODO
return false;
/*
Pix tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
Page page = Engine.Process(tessImage);
// Get the iterator for the page layout
using (var iter = page.GetIterator())
{
// Loop over the elements of the page layout
iter.Begin();
do
{
// Declare a Rect variable to hold the bounding box
Rect boundingBox;
// Get the bounding box for the current element
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
{
//g.DrawRectangle(Pens.Red, new Rectangle(boundingBox.X1, boundingBox.Y1, boundingBox.Width, boundingBox.Height));
}
// Get the text for the current element
var text = iter.GetText(PageIteratorLevel.Word);
//MessageBox.Show(text.ToUpper() + Environment.NewLine);
} while (iter.Next(PageIteratorLevel.Word));
}
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "testDRS"+ ".png");
page.Dispose();
*/
/*
string result = GetStringFromPng();
//if (result == "")
//result = "DRS_OPENED";
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + result+ rnd.Next(0,10000) +".png");
*/
bool result = false;
int greenValue = GetGreenPixels();
if (EmptyDrsGreenValue == -1)
EmptyDrsGreenValue = greenValue;
if (greenValue > EmptyDrsGreenValue + EmptyDrsGreenValue / 100 * 30)
result = true;
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "DRS" + result + ".png");
return result;
}
private int GetGreenPixels()
{
int tot = 0;
for (int y = 0; y < WindowImage.Height; y++)
{
for (int x = 0; x < WindowImage.Width; x++)
{
Color pxlColor = WindowImage.GetPixel(x, y);
if (pxlColor.G > pxlColor.B * 1.5 && pxlColor.G > pxlColor.R * 1.5)
{
tot++;
}
}
}
return tot;
}
public Rectangle GetBox()
{
var tessImage = Pix.LoadFromMemory(ImageToByte(WindowImage));
Engine.SetVariable("tessedit_char_whitelist", "");
Page page = Engine.Process(tessImage);
using (var iter = page.GetIterator())
{
iter.Begin();
do
{
Rect boundingBox;
// Get the bounding box for the current element
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
{
page.Dispose();
return new Rectangle(boundingBox.X1, boundingBox.X2, boundingBox.Width, boundingBox.Height);
}
} while (iter.Next(PageIteratorLevel.Word));
page.Dispose();
return new Rectangle(0, 0, 0, 0);
}
}
}
}
+4
View File
@@ -9,12 +9,16 @@ namespace OCR_Decode
{
internal class DriverTyresWindow : Window
{
private static Random rnd = new Random();
public DriverTyresWindow(Bitmap image, Rectangle bounds) : base(image, bounds)
{
Name = "Tyres";
}
public override object DecodePng()
{
WindowImage.Save(Reader.DEBUG_DUMP_FOLDER + "testTyres" + rnd.Next(0, 1000) + ".png");
return new Tyre(Tyre.Type.Undefined, 0);
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ namespace OCR_Decode
//This should be configurable
const string CONFIG_FILE = @"C:\Users\Moi\Desktop\imgDump\Dump1.json";
const string TEMPORARY_IMAGE_FOLDER = @"C:\Users\Moi\Pictures\SeleniumScreens\DataSetHighRes\";
int pageNmbr = 9;
int pageNmbr = 82;
Reader Reader;
public Form1()
{
+1 -1
View File
@@ -30,7 +30,7 @@ namespace OCR_Decode
{
ConfigFile = configFile;
ImagesFolder = imageFolder;
Load(9);
Load(82);
}
private void Load(int imageNumber)
{