错误消息: 无法加载文件或程序集“openalpr-net,Version=2.3.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。试图加载格式不正确的程序。
但是当我通过命令行运行 alpr.exe 时,它没有任何问题。
这是我的代码:
private void CallAlpr()
{
var openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
OpenAlpr.Output(openFileDialog.FileName);
}
Console.Read();
}
OpenAlpr 类:
using ......
using openalprnet;
using System.Drawing;
public static List<AlprPlateResultNet> RecognizePlate(string imagePath)
{
var alpr = new AlprNet("en", "/openalpr_64/openalpr.conf", "/openalpr_64/runtime_data");
if (!alpr.IsLoaded())
{
throw new Exception("OpenAlpr failed to load!");
}
alpr.DefaultRegion = "md";
var results = alpr.Recognize(imagePath);
return results?.Plates;
}
public static void Output(string imagePath)
{
var plates = RecognizePlate(imagePath);
var i = 0;
foreach (var result in plates)
{
Console.WriteLine("Plate {0}:{1} result(s)", i++, result.TopNPlates.Count);
Console.WriteLine(" Processing Time: {0} msec(s)", result.ProcessingTimeMs);
foreach (var plate in result.TopNPlates)
{
Console.WriteLine(" - {0}\t Confidence: {1}\tMatches Template: {2}",
plate.Characters, plate.OverallConfidence, plate.MatchesTemplate);
}
}
}
我的项目文件夹下有文件夹:openalpr_64。