Error message: Could not load file or assembly 'openalpr-net, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
But when I run the alpr.exe by commend line, it does not have any issues.
Here is my code:
private void CallAlpr()
{
var openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
OpenAlpr.Output(openFileDialog.FileName);
}
Console.Read();
}
OpenAlpr class:
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);
}
}
}
I have the folder: openalpr_64 under my project folder.
I solved this problem by copying all files and folders from the zip file to Debug folder and made sure the the .config and runtime_data pointed to the right path.