Files
TrackTrendsDoc/temp_annexes/Code/DriverPositionWindow.md
T
2023-06-05 16:17:17 +02:00

1.2 KiB

DriverPositionWindow.cs

/// Author : Maxime Rohmer
/// Date : 30/05/2023
/// File : DriverPositionWindow.cs
/// Brief : Window containing infos about the position of a driver.
/// Version : Alpha 1.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace TrackTrends
{
    public class DriverPositionWindow:Window
    {
        public DriverPositionWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
        {
            Name = "Position";
        }
        /// <summary>
        /// Decodes the position number using Tesseract OCR
        /// </summary>
        /// <returns>An int representing the position of the driver (should be between 1 and 20 included)</returns>
        public override object DecodePng()
        { 
            string ocrResult = GetStringFromPng(WindowImage, Engine, "0123456789");

            int position;
            try
            {
                position = Convert.ToInt32(ocrResult);
            }
            catch
            {
                position = -1;
            }
            return position;
        }
    }
}