如何在 Ubuntu 18.04 上 运行 OpenCvSharp?

How to run OpenCvSharp on Ubuntu 18.04?

我在 Ubuntu Linux 上使用 运行ning OpenCvShare 时遇到问题。一直提示找不到libOpenCvSharpExtern

我在 Ubuntu 18.04.1 x64 上使用 运行ning OpenCvSharp 时遇到问题。我创建了一个 .NET Core/Standard 解决方案(Standard 是一个库项目,Core 是 运行ner)。库项目引用 Nuget 包: OpenCvSharp4 (4.0.0.20181225) OpenCvSharp4.runtime.ubuntu.18.04-x64 (4.0.0.20181225).

然后,在编译成功后,我发布了 运行ner 项目使用:

dotnet publish -c Release -r ubuntu.18.04-x64

然后,当我 运行 Ubuntu 上的可执行文件时,抛出以下错误:

Unhandled Exception: OpenCvSharp.OpenCvSharpException: Failed to create VideoCapture System.TypeInitializationException: The type initializer for 'OpenCvSharp.NativeMethods' threw an exception. OpenCvSharp.OpenCvSharpException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libOpenCvSharpExtern: cannot open shared object file: No such file or directory ---> System.DllNotFoundException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libOpenCvSharpExtern: cannot open shared object file: No such file or directory

文件 libOpenCvSharpExtern.so 与可执行文件位于同一路径,我也将其复制到 usr/local/lib 中,但 id 没有帮助。应用程序旨在根据相机输入检测面部。

好的,我终于明白了运行。问题出在包含路径中。当你执行 ldd libOpenCvSharpExtern.so 从 lib 所在路径中的终端,它将输出此库使用的所有引用库。最初我有 "not found" 参考文献的完整列表。 /usr/local/lib 中已安装所有缺少的库。事实证明,这条路径不是系统寻找库的默认路径。 Link to a question on ubuntu forum

我添加后 export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib" 环境变量并重新启动系统,一切都开始工作,并且在 libOpenCvSharpExtern.so 库上使用 ldd 清楚地显示,所有库都已找到。