首页 > 解决方案 > 使用 EmguCV 在 Ubuntu 20.04 上的 System.DllNotFoundException

问题描述

尝试使用 EmguCv,所以我制作了一个测试控制台应用程序,在 Windows 10 上运行良好,但在 Ubuntu 20.04 上它只是不想工作,它抛出异常(更多下文),如何解决?

如何重现/我尝试过的

复制存储库并转到步骤 5 或手动复制:

  1. 创建控制台应用程序
  2. 添加以下 NuGet 包:
  1. 将此代码插入Program.cs
  2. 发布您的应用程序:

dotnet publish -c release -r ubuntu.20.04-x64

  1. 将项目复制到ubuntu
  2. 在 ubuntu CLI 中,导航到发布文件夹

cd EmguTest/bin/Release/net5.0/ubuntu.20.04-x64/publish

  1. 提供执行权限:

chmod 777 ./EmguTestUbuntu

  1. 执行应用程序并查看错误

./EmguTestUbuntu

信息

该应用程序是在Windows 10 上的 Visual Studio Community 2019中创建的。执行代码的操作系统是安装了 dotnet 和 git的Oracle VM VirtualBox上的全新Ubuntu 20.04 。在此页面上阅读有关如何在 Linux 上运行应用程序的信息,这就是我使用的步骤,但不确定这是否是我试图在 Windows 上编译和构建应用程序到 Linux 的内容。

代码

    class Program
    {
        static QRCodeDetector detector;
        static VideoCapture videoCapture = new();
        private static ManualResetEvent waitHandle = new ManualResetEvent(false);

        static void Main(string[] args)
        {
            Console.WriteLine("Started!");
            videoCapture.ImageGrabbed += Capture_ImageGrabbed;
            detector = new();
            videoCapture.Start();
            waitHandle.WaitOne();
        }

        private static void Capture_ImageGrabbed(object sender, EventArgs e)
        {
            Console.WriteLine("capturing");
            try
            {
                Mat m = new();
                Mat o = new();
                videoCapture.Retrieve(m);
                var qrs = detector.Detect(m, o);
                if (qrs)
                {
                    string code = detector.Decode(m, o, new Mat());
                    if (code != "")
                    {
                        Console.WriteLine(code);
                    }
                }
            }
            catch (Exception ex)
            {
                videoCapture.ImageGrabbed -= Capture_ImageGrabbed;
                videoCapture.Stop();
                videoCapture = null;
                Console.WriteLine(ex.Message);
                throw;
            }
        }
    }

日志

Started!
Unhandled exception. System.TypeInitializationException: The type initializer for 'ConsoleApp1.Program' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'dl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libdl: cannot open shared object file: No such file or directory
   at Emgu.Util.Toolbox.Dlopen(String dllname, Int32 mode)
   at Emgu.Util.Toolbox.LoadLibrary(String dllname)
   at Emgu.CV.CvInvoke.LoadUnmanagedModules(String loadDirectory, String[] unmanagedModules)
   at Emgu.CV.CvInvoke.DefaultLoadUnmanagedModules(String[] modules)
   at Emgu.CV.CvInvoke..cctor()
   --- End of inner exception stack trace ---
   at Emgu.CV.CvInvoke.cveVideoCaptureCreateFromDevice(Int32 index, API apiPreference)
   at Emgu.CV.VideoCapture..ctor(Int32 camIndex, API captureApi)
   at ConsoleApp1.Program..cctor() in E:\Vsprojects\EmguTestV2\EmguTestUbuntu\Program.cs:line 10
   --- End of inner exception stack trace ---
   at ConsoleApp1.Program.Main(String[] args) in E:\Vsprojects\EmguTestV2\EmguTestUbuntu\Program.cs:line 16
Aborted (core dumped)

标签: c#opencvubuntuwebcamemgucv

解决方案


推荐阅读