Open Alpr无法加载其依赖项

时间:2017-01-16 01:34:14

标签: c# openalpr

错误讯息: 无法加载文件或程序集' 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文件夹。

2 个答案:

答案 0 :(得分:2)

根据我的经验,我在尝试使用不是32位或64位的C#DLLs / .EXE时才看到该特定消息。

检查您的项目构建是否未设置为“任何CPU”(在64位操作系统上默认为64位)。

至少,检查.EXE和库.DLL的32/64位。

祝你好运!

答案 1 :(得分:0)

我通过将zip文件中的所有文件和文件夹复制到Debug文件夹来解决了这个问题,并确保.config和runtime_data指向正确的路径。

相关问题