c# - 使用 EmguCV 在 Ubuntu 20.04 上的 System.DllNotFoundException
问题描述
尝试使用 EmguCv,所以我制作了一个测试控制台应用程序,在 Windows 10 上运行良好,但在 Ubuntu 20.04 上它只是不想工作,它抛出异常(更多下文),如何解决?
如何重现/我尝试过的
复制此存储库并转到步骤 5 或手动复制:
- 创建控制台应用程序
- 添加以下 NuGet 包:
- Emgu.CV
- Emgu.CV.runtime.windows
- Emgu.CV.runtime.ubuntu.20.04-x64
- 将此代码插入Program.cs
- 发布您的应用程序:
dotnet publish -c release -r ubuntu.20.04-x64
- 将项目复制到ubuntu
- 在 ubuntu CLI 中,导航到发布文件夹
cd EmguTest/bin/Release/net5.0/ubuntu.20.04-x64/publish
- 提供执行权限:
chmod 777 ./EmguTestUbuntu
- 执行应用程序并查看错误
./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)
解决方案
推荐阅读
- typescript - 如何在 ngx-admin 模板中使组件全屏显示?
- javascript - 计算仪表值以绘制仪表 svg 路径的公式
- react-native - 在 react native 天才聊天中,哪些道具用于在工具栏中添加图像和相机等额外功能?我如何实现它?
- haskell - 将自身作为参数的函数的 Hindley-Milner 类型
- javascript - 如何将 Javascript 文件动态加载到 HTML 中
- angular - 角度滚动到动态创建的元素
- python - 如何在预训练的 Keras CNN 模型中更改图层的形状?
- node.js - 如何将数据推送到nodejs mongodb中的另一个模式
- javascript - 在asp.net mvc的Index.cshtml中没有定义部分?
- java - 如何将双精度值转换为 java 中的 n 个位置(给出答案,而不是问问题)