Exemplo n.º 1
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);
        }