From 08a217638519b7e9c363df291f861979b26ca305 Mon Sep 17 00:00:00 2001 From: maxluli Date: Sat, 8 Apr 2023 08:45:57 +0200 Subject: [PATCH] Now the color recognition is better --- OCR_Decode/DriverTyresWindow.cs | 18 ++++++++++-------- OCR_Decode/OcrImage.cs | 5 +++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/OCR_Decode/DriverTyresWindow.cs b/OCR_Decode/DriverTyresWindow.cs index 82a1602..921d230 100644 --- a/OCR_Decode/DriverTyresWindow.cs +++ b/OCR_Decode/DriverTyresWindow.cs @@ -38,15 +38,16 @@ namespace OCR_Decode tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "ZONE" + ".png"); Tyre.Type type = Tyre.Type.Undefined; int laps = -1; - if (text.All(char.IsDigit)) - { + //if (text.All(char.IsDigit)) + //{ //We have a lap count - if (text != "") - { - laps = Convert.ToInt32(text); - type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(tyreZone)); - } - } + //if (text != "") + //{ + //laps = Convert.ToInt32(text); + type = GetTyreTypeFromColor(OcrImage.GetAvgColorFromBitmap(OcrImage.Resize(tyreZone))); + //} + //} + /* else { //We have a tire type @@ -74,6 +75,7 @@ namespace OCR_Decode break; } } + */ tyreZone.Save(Reader.DEBUG_DUMP_FOLDER + "Tyre" + type + "Laps" + laps + '#' + rnd.Next(0, 1000) + ".png"); return new Tyre(type,laps); } diff --git a/OCR_Decode/OcrImage.cs b/OCR_Decode/OcrImage.cs index b3b9917..7e861e2 100644 --- a/OCR_Decode/OcrImage.cs +++ b/OCR_Decode/OcrImage.cs @@ -201,7 +201,8 @@ namespace OCR_Decode int R = pixel[2]; //We remove the background pixels - if (R >= limitColor.R && G >= limitColor.G && B >= limitColor.B) + + if (R >= limitColor.R || G >= limitColor.G || B >= limitColor.B) { totPixels++; totB += pixel[0]; @@ -213,7 +214,7 @@ namespace OCR_Decode } bmp.UnlockBits(bmpData); - return Color.FromArgb(255,totR / totPixels,totG / totPixels,totB / totPixels); + return Color.FromArgb(255,Convert.ToInt32((float)totR / (float)totPixels),Convert.ToInt32((float)totG / (float)totPixels),Convert.ToInt32((float)totB / (float)totPixels)); } public static Bitmap InvertColors(Bitmap input) {