Beispiel #1
0
        static void Main(string[] args)
        {
            var alpr = new AlprNet(DEFAULT_PAIS, RUTA_CONF, RUTA_RUNTIME_DATA);

            if (!alpr.isLoaded())
            {
                Console.WriteLine(MENSAJE_ERROR_CARGA);
                return;
            }

            // Opcional, configurar el patron para una region en particular
            alpr.DefaultRegion = DEFAULT_REGION;

            var resultados = alpr.recognize(IMAGEN_PLACA_EJEMPLO);
            int i          = 0;

            foreach (var resultado in resultados.plates)
            {
                Console.WriteLine(MENSAJE_INICIO_RESULTADO, i++, resultado.topNPlates.Count);
                Console.WriteLine(MENSAJE_TIEMPO_PROCESAMIENTO, resultado.processing_time_ms);

                foreach (var placa in resultado.topNPlates)
                {
                    Console.WriteLine(MENSAJE_RESULTADO_FINAL, placa.characters,
                                      placa.overall_confidence, placa.matches_template);
                }
            }

            Console.ReadKey();
        }
        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 alpr = new AlprNet(region, config);
            if (!alpr.isLoaded())
            {
                Console.WriteLine("OpenAlpr failed to loaded!");
                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);
        }
Beispiel #3
0
        private void processImageFile(string fileName)
        {
            resetControls();
            var    region           = rbUSA.Checked ? "us" : "eu";
            String config_file      = Path.Combine(AssemblyDirectory, "openalpr.conf");
            String runtime_data_dir = Path.Combine(AssemblyDirectory, "runtime_data");

            using (var alpr = new AlprNet(region, config_file, runtime_data_dir))
            {
                if (!alpr.isLoaded())
                {
                    lbxPlates.Items.Add("Error initializing OpenALPR");
                    return;
                }
                picOriginal.ImageLocation = fileName;
                picOriginal.Load();

                var results = alpr.recognize(fileName);

                var images = new List <Image>(results.plates.Count());
                var i      = 1;
                foreach (var result in results.plates)
                {
                    var rect    = boundingRectangle(result.plate_points);
                    var img     = Image.FromFile(fileName);
                    var cropped = cropImage(img, rect);
                    images.Add(cropped);

                    lbxPlates.Items.Add("\t\t-- Plate #" + i++ + " --");
                    foreach (var plate in result.topNPlates)
                    {
                        lbxPlates.Items.Add(string.Format(@"{0} {1}% {2}",
                                                          plate.characters.PadRight(12),
                                                          plate.overall_confidence.ToString("N1").PadLeft(8),
                                                          plate.matches_template.ToString().PadLeft(8)));
                    }
                }

                if (images.Any())
                {
                    picLicensePlate.Image = combineImages(images);
                }
            }
        }
        /// <summary>
        /// Gets all license plate matches for their confidence for given image
        /// </summary>
        /// <param name="country">Country (US / EU)</param>
        /// <param name="imagePath">Image path</param>
        /// <returns>License plate matches for their confidence</returns>
        public List<Result> GetPlateNumberCandidates(Country country, string imagePath)
        {
            var ass = Assembly.GetExecutingAssembly();
            var assemblyDirectory = Path.GetDirectoryName(ass.Location);

            var configFile = Path.Combine(assemblyDirectory, "openalpr", "openalpr.conf");
            var runtimeDataDir = Path.Combine(assemblyDirectory, "openalpr", "runtime_data");
            using (var alpr = new AlprNet(country == Country.EU ? "eu" : "us", configFile, runtimeDataDir))
            {
                if (!alpr.isLoaded())
                {
                    throw new Exception("Error initializing OpenALPR");
                }

                var results = alpr.recognize(imagePath);
                return results.plates.SelectMany(l => l.topNPlates.Select(plate => new Result
                {
                    PlateNumber = plate.characters,
                    Confidence = plate.overall_confidence
                })).ToList();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets all license plate matches for their confidence for given image
        /// </summary>
        /// <param name="country">Country (US / EU)</param>
        /// <param name="imagePath">Image path</param>
        /// <returns>License plate matches for their confidence</returns>
        public List <Result> GetPlateNumberCandidates(Country country, string imagePath)
        {
            var ass = Assembly.GetExecutingAssembly();
            var assemblyDirectory = Path.GetDirectoryName(ass.Location);

            var configFile     = Path.Combine(assemblyDirectory, "openalpr", "openalpr.conf");
            var runtimeDataDir = Path.Combine(assemblyDirectory, "openalpr", "runtime_data");

            using (var alpr = new AlprNet(country == Country.EU ? "eu" : "us", configFile, runtimeDataDir))
            {
                if (!alpr.isLoaded())
                {
                    throw new Exception("Error initializing OpenALPR");
                }

                var results = alpr.recognize(imagePath);
                return(results.plates.SelectMany(l => l.topNPlates.Select(plate => new Result
                {
                    PlateNumber = plate.characters,
                    Confidence = plate.overall_confidence
                })).ToList());
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        private void processImageFile(string fileName)
        {
            resetControls();
            var region = rbUSA.Checked ? "us" : "eu";
            String config_file =  Path.Combine(AssemblyDirectory, "openalpr.conf");
            String runtime_data_dir = Path.Combine(AssemblyDirectory, "runtime_data");
            using (var alpr = new AlprNet(region, config_file, runtime_data_dir))
            {
                if (!alpr.isLoaded())
                {
                    lbxPlates.Items.Add("Error initializing OpenALPR");
                    return;
                }
                picOriginal.ImageLocation = fileName;
                picOriginal.Load();

                var results = alpr.recognize(fileName);

                var images = new List<Image>(results.plates.Count());
                var i = 1;
                foreach (var result in results.plates)
                {
                    var rect = boundingRectangle(result.plate_points);
                    var img = Image.FromFile(fileName);
                    var cropped = cropImage(img, rect);
                    images.Add(cropped);

                    lbxPlates.Items.Add("\t\t-- Plate #" + i++ + " --");
                    foreach (var plate in result.topNPlates)
                    {
                        lbxPlates.Items.Add(string.Format(@"{0} {1}% {2}",
                                                          plate.characters.PadRight(12),
                                                          plate.overall_confidence.ToString("N1").PadLeft(8),
                                                          plate.matches_template.ToString().PadLeft(8)));
                    }
                }

                if (images.Any())
                {
                    picLicensePlate.Image = combineImages(images);
                }
            }
        }