在 linux 上运行 Emgu.CV [英] Running Emgu.CV on linux

查看:22
本文介绍了在 linux 上运行 Emgu.CV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Linux 上使用 Emgu,但出现错误留言:

I am attempting to use Emgu on linux, but getting the error message:

未处理的异常.System.TypeInitializationException:
Emgu.CV.CvInvoke"的类型初始值设定项引发异常.
--->System.DllNotFoundException:无法加载共享库cvextern"或其依赖项之一

Unhandled exception. System.TypeInitializationException:
The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'cvextern' or one of its dependencies

SO文档 我知道我需要:

确保非托管 DLL 位于执行目录中.

Make sure the unmanaged DLLs are in the execution directory.

但是 - 我如何获得它们?
如果我在 Windows 机器上运行相同的项目(+ 取消注释对 Emgu.CV.runtime.windows 包的引用),我确实得到 x86 &x64 文件夹在我的 bin 文件夹中,我可以从中获取二进制文件,但显然在使用 Emgu.CV.runtime.ubuntu 包时,不会创建这些文件夹.

But - how do I get them?
If I run the same project on a windows machine (+ un commenting the reference to the Emgu.CV.runtime.windows package), I indeed get x86 & x64 folders in my bin folder which I can get the binaries from, but apparently when using Emgu.CV.runtime.ubuntu package, those folders are not created.

最小的、可重复的示例:
Program.cs:

using Emgu.CV;
using Emgu.CV.Structure;
using System;

namespace temp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Works on windows, fails on linux
            var imageFromBytes = new Image<Rgb, byte>(2, 2);


            //// Later on I would like this to work as well...
            // var bytes = new byte[] { 1, 2, 3, 4 };
            // CvInvoke.Imdecode(bytes, Emgu.CV.CvEnum.ImreadModes.Color, imageFromBytes.Mat);
        }

    }
}

项目文件:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Emgu.CV.runtime.ubuntu" Version="4.4.0.4061" />

    <!-- When running on windows & uncommenting this line - I get can get the binaries-->
    <!-- <PackageReference Include="Emgu.CV.runtime.windows" Version="4.4.0.4061" /> -->

  </ItemGroup>

</Project>


其他信息:
dotnet 版本:3.1.301
Emgu版本:4.4.0.4061


Additional information:
dotnet version: 3.1.301
Emgu version: 4.4.0.4061

推荐答案

所以,经过几天的挣扎 - 回答我自己的问题.

So, after few days of struggling - answering my own question.

据我所知,这里有两个问题:

As far as I understand, there were two issues here:

  1. libcvextern.so 丢失.
  2. libcvextern.so 依赖项缺失.
  1. libcvextern.so was missing.
  2. libcvextern.so dependencies were missing.

解决问题:

1.缺少 libcvextern.so:

  1. 下载了 Emgu.CV.runtime.ubuntu
  2. 解压并得到 libcvextern.so 文件 (build/x64/libcvextern.so).
  3. 在项目中添加libcvextern.so文件,并将Copy to Output directory设置为Copy if Newer
  1. Downloaded the Emgu.CV.runtime.ubuntu
  2. unzip it and get the libcvextern.so file (build/x64/libcvextern.so).
  3. Add the libcvextern.so file to the project and set Copy to Output directory to Copy if Newer

注意:对于 windows nuget 包,您需要的文件会自动添加.不知道为什么这不会发生在 linux 上.

Note: For the windows nuget package the files that you need are added automatically. Not sure why this does not happen for linux.

2.缺少依赖项:

  1. 根据文档(Linux -> 准备),我已经克隆了 repo 并运行了确保安装了所有依赖项的脚本:
  1. As per the documentation (Linux -> Getting ready), I have cloned the repo and ran the script that makes sure that all dependencies are installed:

获取 dotnet 框架:

get dotnet Framework:

wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb

获取源代码:

git clone https://github.com/emgucv/emgucv emgucv 
cd emgucv
git submodule update --init --recursive

确保依赖项可用:

# cd into the relevant platform
cd platforms/ubuntu/20.04

# As per documentation: This only needs to be run once.
./apt_install_dependency

# This is what actually builds the dependencies. This will take a while...
./cmake_configure


奖励:
如果你和我一样,对你的机器没有 root 权限,你可以使用 docker.
我使用过的 Dockerfile:


Bonus:
If you, like me, don't have root permissions to your machine, you can use docker.
The Dockerfile I have used:

FROM ubuntu
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8


# Bring the dotnet Framework
RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update; \
  apt-get install -y apt-transport-https && \
  apt-get update && \
  apt-get install -y dotnet-sdk-3.1


# Make sure all emgu dependencies are in place
# http://www.emgu.com/wiki/index.php/Download_And_Installation#Getting_ready
WORKDIR /mnt/emgu_repo
RUN git clone https://github.com/emgucv/emgucv emgucv
WORKDIR /mnt/emgu_repo/emgucv
RUN git submodule update --init --recursive
WORKDIR /mnt/emgu_repo/emgucv/platforms/ubuntu/18.04
RUN apt-get update && apt-get -y install sudo
RUN `cat ./apt_install_dependency.sh | grep -Ev "\#\!"` -y
RUN ./cmake_configure.sh


ENTRYPOINT ["bash"]

这篇关于在 linux 上运行 Emgu.CV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆