private static void PerformAlpr(AlprNet alpr, byte[] buffer, bool benchmark, bool writeJson) { var sw = Stopwatch.StartNew(); sbyte[] signedBuffer = (sbyte[])(Array)buffer; var results = alpr.recognize(signedBuffer); sw.Stop(); if (benchmark) { Console.WriteLine("Total Time to process image(s): {0} msec(s)", sw.ElapsedMilliseconds); } if (writeJson) { //Console.WriteLine(alpr.toJson()); } else { var i = 0; foreach (var result in results.plates) { Console.WriteLine("Plate {0}: {1} result(s)", i++, result.topNPlates.Count); Console.WriteLine(" Processing Time: {0} msec(s)", result.processing_time_ms); foreach (var plate in result.topNPlates) { Console.WriteLine(" - {0}\t Confidence: {1}\tMatches Template: {2}", plate.characters, plate.overall_confidence, plate.matches_template); } } } }
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 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(); } }
/// <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()); } }
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); } } }