public static void Main()
        {
            var alpr = new AlprNet(
                "eu",
                Environment.CurrentDirectory + @"\openalpr.conf",
                Environment.CurrentDirectory + @"\runtime_data");

            if (!alpr.IsLoaded())
            {
                Console.WriteLine("OpenAlpr failed to load!");
                return;
            }

            Console.WriteLine($"Version: {AlprNet.GetVersion()}");
            var results = alpr.Recognize(Environment.CurrentDirectory + @"\samples\niki_ivo.jpg");

            for (int index = 0; index < results.Plates.Count; index++)
            {
                var result = results.Plates[index];
                Console.WriteLine($"Plate {index}: {result.TopNPlates.Count} result(s)");
                Console.WriteLine($"  Processing Time: {result.ProcessingTimeMs} msec(s)");
                foreach (var plate in result.TopNPlates)
                {
                    Console.WriteLine(
                        $"  - {plate.Characters}\t Confidence: {plate.OverallConfidence}\tMatches Template: {plate.MatchesTemplate}");
                }
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            var region       = "us";
            var detectRegion = false;
            var benchmark    = false;
            var json         = false;
            var filename     = string.Empty;


            args.Process(
                () => Console.WriteLine("Usage: r=us/eu b=0/1 j=0/1 d=0/1 f=<filename>"),
                new CommandLine.Switch("r",
                                       val => { if (val.Any())
                                                {
                                                    region = val.First().Trim().ToLower();
                                                }
                                       }),
                new CommandLine.Switch("b",
                                       val => { if (val.Any())
                                                {
                                                    benchmark = StrToBool(val.First());
                                                }
                                       }),
                new CommandLine.Switch("j",
                                       val => { if (val.Any())
                                                {
                                                    json = StrToBool(val.First());
                                                }
                                       }),
                new CommandLine.Switch("d",
                                       val => { if (val.Any())
                                                {
                                                    detectRegion = StrToBool(val.First());
                                                }
                                       }),
                new CommandLine.Switch("f",
                                       val => { if (val.Any())
                                                {
                                                    filename = val.First().Trim();
                                                }
                                       })
                );

            Console.WriteLine("OpenAlpr Version: {0}", AlprNet.GetVersion());
            var config       = Path.Combine(AssemblyDirectory, "openalpr.conf");
            var runtime_data = Path.Combine(AssemblyDirectory, "runtime_data");
            var alpr         = new AlprNet(region, config, runtime_data);

            if (!alpr.IsLoaded())
            {
                Console.WriteLine("OpenAlpr failed to load!");
                return;
            }

            //var samplePath = Path.Combine(AssemblyDirectory, @"samples\eu-1.jpg");
            //alpr.TopN = 3;
            alpr.DefaultRegion = region;
            alpr.DetectRegion  = detectRegion;

            if (Directory.Exists(filename))
            {
                var files = Directory.GetFiles(filename, "*.jpg", SearchOption.TopDirectoryOnly);
                foreach (var fname in files)
                {
                    PerformAlpr(alpr, fname, benchmark, json);
                }
                return;
            }

            if (!File.Exists(filename))
            {
                Console.WriteLine("The file doesn't exist!");
                return;
            }
            var buffer = File.ReadAllBytes(filename);

            PerformAlpr(alpr, buffer, benchmark, json);
        }