using System;
using System.Linq;
using OpenCvSharp;

namespace OCR
{
    public class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                var convolutionNeuralNet = new ConvolutionNeuralNet();
                //numeric model
                convolutionNeuralNet.TrainAndSave(10, "numbers", false);
                //lower model
                convolutionNeuralNet.TrainAndSave(26, "lower", false);
                //upper model
                convolutionNeuralNet.TrainAndSave(26, "upper", false);
            } catch (Exception e) {
                Console.WriteLine($"Training or validating not successfull: {e.Message}");
            }
            
            //load image
            Mat image;
            if (args.Any()) {
                image = Cv2.ImRead(args[0]);
            } else {
                image = Cv2.ImRead("25 - Critical error.png");
            }
            var evaluationChain = new EvaluationChain();
            Console.WriteLine("EVALUATION STARTED.");
            var evaluationResults = evaluationChain.ProcessEvaluationChain(image);
            Console.WriteLine("EVALUATION FINISHED.");
            evaluationResults.PrintOutput();
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}