linux 错误无法在Ubuntu上使用.Net Core 3.1加载文件或程序集Tesseract

nr9pn0ug  于 2022-11-22  发布在  Linux
关注(0)|答案(3)|浏览(201)

我正在dotnetcore 3.1项目上使用Tesseract版本4.1.1,它在windows上运行得很好,但是当我在ubuntu上发布它时,它在此行中抛出了以下错误

new TesseractEngine(Tessdatapath, LanguageCode, EngineMode.TesseractAndLstm);

Could not load file or assembly 'Tesseract, Version=4.1.1.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
我将x64和x86 dll与发布文件一起复制,并确保它们与tessdata处于同一级别
我试着在ubuntu上安装tesseract,并复制了x64和x86文件夹中的.so文件,但仍然没有运气

vfh0ocws

vfh0ocws1#

我是这么解决的
原来系统没有显示正确的错误信息,因为它不能使用Linux不支持的System.Drawing.Common库。
通过使用libgdiplux修复了System.Drawing.Common的Linux实现

sudo apt-get -f install libgdiplus

然后显示正确的消息,即

Failed to find library "libleptonica-1.80.0.so" for platform x64.

为了解决这个问题,我不得不从这里编译这个leptonica版本http://www.leptonica.org/download.html
这有助于我编译它http://www.leptonica.org/source/README.html
因此,现在我有“libleptonica-1.80.0.so“安装我创建了我的x64文件夹内的leptonica文件链接以下评论Tesseract问题#503

9rnv2umw

9rnv2umw2#

由于我不得不做了很多试验和错误,即使从@Lemo伟大的答案,我想张贴我的结果Docker文件,因为它可能会保存一些人几个小时:)

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80

# Install libs for Tesseract
RUN apt-get update
RUN apt-get install -y git cmake build-essential
RUN mkdir leptonica
RUN git clone https://github.com/DanBloomberg/leptonica.git /leptonica

WORKDIR /leptonica
RUN mkdir build
WORKDIR /leptonica/build
RUN cmake ..

RUN apt-get install -y libleptonica-dev libtesseract-dev

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["ProjectName/ProjectName.csproj", "ProjectName/"]
RUN dotnet restore "ProjectName/ProjectName.csproj"
COPY . .

WORKDIR "/src/ProjectName"
RUN dotnet build "ProjectName.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ProjectName.csproj" -c Release -o /app/publish

FROM base AS final
# Link libs for Tesseract
WORKDIR /app/x64
RUN ln -s /usr/lib/x86_64-linux-gnu/liblept.so.5 libleptonica-1.80.0.so
RUN ln -s /usr/lib/x86_64-linux-gnu/libtesseract.so.4.0.1 libtesseract41.so
# Entrypoint
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectName.dll"]
uhry853o

uhry853o3#

这里所描述的一切对我来说都不起作用。
不管我做了什么,我一直收到"libleptonica-1.80.0.so error for platform x64"
问题出在宇宙魔方库里面。有人做了一个补丁,用反射来修复。他的评论在这里。
这对我来说是完美的。我将在这里留下完整的Dockerfile代码沿着我如何使它工作的步骤。
1.将这些文件libleptonica-1.80.0.so, libtesseract41.so放入您的项目文件夹中,文件路径与这个家伙在他的项目中创建的文件路径相同:<your_solution>/<project>/runtimes/linux-x64/native/
1.将此类TesseractLinuxLoaderFix.cs添加到项目中
1.在使用Tesseract之前调用Path方法。TesseractLinuxLoaderFix.Patch();
1.将您的Dockerfile描述为:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

# Install libs for Tesseract. Despite this build a few libraries still will be not available
RUN apt-get update
RUN apt-get install -y git cmake build-essential
RUN mkdir leptonica
RUN git clone --depth 1 --branch 1.80.0 https://github.com/DanBloomberg/leptonica.git /leptonica 
RUN cd leptonica

WORKDIR /leptonica
RUN mkdir build
WORKDIR /leptonica/build
RUN cmake ..

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "SolutionName/ProjectName.csproj"
COPY . .
WORKDIR "/src/ProjectName"
RUN dotnet build "ProjectName.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ProjectName.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

# copy Tesseract missing dependencies
COPY --from=build /src/ProjectName/runtimes ./runtimes

ENTRYPOINT ["dotnet", "ProjectName.dll"]

那我就万事大吉了。最后。祝大家好运

相关问题