From fa07045199ec53d4068de7d2c37ffb8f2263efb0 Mon Sep 17 00:00:00 2001 From: maxluli Date: Tue, 25 Apr 2023 11:06:03 +0200 Subject: [PATCH] Slightly improved performances or the tyre recognition --- OCR_Decode/OcrImage.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/OCR_Decode/OcrImage.cs b/OCR_Decode/OcrImage.cs index 6ebe332..d81878b 100644 --- a/OCR_Decode/OcrImage.cs +++ b/OCR_Decode/OcrImage.cs @@ -16,6 +16,7 @@ namespace OCR_Decode { Bitmap InputImage; Random rnd = new Random(); + int salt = 0; public enum WindowType { LapTime, @@ -27,11 +28,11 @@ namespace OCR_Decode public OcrImage(Bitmap inputImage) { InputImage = inputImage; + salt = rnd.Next(0, 10000); } public Bitmap Enhance(WindowType type = WindowType.Text) { Bitmap result = (Bitmap)InputImage.Clone(); - int salt = rnd.Next(0, 10000); switch (type) { case WindowType.LapTime: @@ -57,13 +58,13 @@ namespace OCR_Decode //result.Save(Reader.DEBUG_DUMP_FOLDER + "TextAfter_" + salt + ".png"); break; case WindowType.Tyre: - //result.Save(Reader.DEBUG_DUMP_FOLDER + "tyreBefore_" + salt + ".png"); + result.Save(Reader.DEBUG_DUMP_FOLDER + "tyreBefore_" + salt + ".png"); result = RemoveUseless(result); - //result.Save(Reader.DEBUG_DUMP_FOLDER + "tyre01_" + salt + ".png"); + result.Save(Reader.DEBUG_DUMP_FOLDER + "tyre01_" + salt + ".png"); result = Resize(result, 4); - //result.Save(Reader.DEBUG_DUMP_FOLDER + "tyre02_" + salt + ".png"); + result.Save(Reader.DEBUG_DUMP_FOLDER + "tyre02_" + salt + ".png"); result = Dilatation(result, 1); - //result.Save(Reader.DEBUG_DUMP_FOLDER + "tyreAfter_" + salt + ".png"); + result.Save(Reader.DEBUG_DUMP_FOLDER + "tyreAfter_" + salt + ".png"); break; default: result = Tresholding(result, 165); @@ -173,7 +174,10 @@ namespace OCR_Decode } public unsafe static Bitmap RemoveUseless(Bitmap bmp) { - bmp = RemoveBG(bmp); + Random rnd = new Random(); + int salt = rnd.Next(0,1000); + + //bmp.Save(Reader.DEBUG_DUMP_FOLDER + "RemovedBG_"+salt+".png"); Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat); int bytesPerPixel = Bitmap.GetPixelFormatSize(bmp.PixelFormat) / 8; @@ -257,7 +261,7 @@ namespace OCR_Decode //We remove the background pixels - if (R >= limitColor.R + 20 || G >= limitColor.G + 20 || B >= limitColor.B + 20) + if (R >= limitColor.R + 15 || G >= limitColor.G + 15 || B >= limitColor.B + 15) { pixel[0] = 0xFF; pixel[1] = 0xFF;