-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to load shared library 'OpenCvSharpExtern' VS for Mac Web App deployed using Docker compose #1073
Comments
I'd recommend checking issue I created some time ago for this problem: In short: the only workaround I've found is to build OpenCV and OpenCVSharpExtern right inside your container. Works quite well. |
Thanks for the answer. make[2]: *** [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:154: OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/features2d.cpp.o] Error 1 I tried updating CMake and Make but it didn't solve the issue. |
I just did another try with the dockerfile below but didn't work: FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build ENV OPENCV_VERSION=4.4.0 RUN apt-get update && apt-get install -y Install opencv dependenciesRUN cd ~ RUN cd /usr/include/linux Setup OpenCV sourceRUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && Setup opencv-contrib SourceRUN wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && Build OpenCVRUN cd opencv && mkdir build && cd build && WORKDIR / Download OpenCvSharpRUN git clone https://github.com/shimat/opencvsharp.git Install the Extern lib.WORKDIR /opencvsharp/src FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-dotnet-env Install Build the C# part of OpenCvSharpWORKDIR /opencvsharp/src/OpenCvSharp WORKDIR /opencvsharp/src/OpenCvSharp.Blob WORKDIR /opencvsharp/src/OpenCvSharp.Extensions RUN mkdir /opencvsharp/build WORKDIR /src WORKDIR "/src/ObserVisionWeb" FROM build AS publish FROM base AS final |
Here is the Dockerfile we currently use. The only change from the one I posted is that OpenCV version set to 4.4.0 (latest is 4.5, didn't have time to upgrade and test yet, so be sure to use 4.4.0 NuGet package in your C# app): FROM mcr.microsoft.com/dotnet/core/sdk:3.1-focal
ENV OPENCV_VERSION=4.4.0
RUN apt-get update && apt-get install -y \
apt-transport-https \
software-properties-common \
wget \
unzip \
curl \
ca-certificates
#bzip2 \
#grep sed dpkg
# Install opencv dependencies
RUN cd ~
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
git \
gfortran \
libjpeg8-dev \
libpng-dev \
software-properties-common
RUN add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" && apt-get update && apt-get install -y \
libjasper1 \
libtiff-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libdc1394-22-dev \
libxine2-dev \
libv4l-dev
RUN cd /usr/include/linux
RUN ln -s -f ../libv4l1-videodev.h videodev.h
RUN cd ~
RUN apt-get install -y \
libgtk2.0-dev libtbb-dev qt5-default \
libatlas-base-dev \
libfaac-dev \
libmp3lame-dev \
libtheora-dev \
libvorbis-dev \
libxvidcore-dev \
libopencore-amrnb-dev \
libopencore-amrwb-dev \
libavresample-dev \
x264 \
v4l-utils
# Setup OpenCV source
RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
unzip ${OPENCV_VERSION}.zip && \
rm ${OPENCV_VERSION}.zip && \
mv opencv-${OPENCV_VERSION} opencv
# Setup opencv-contrib Source
RUN wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
unzip ${OPENCV_VERSION}.zip && \
rm ${OPENCV_VERSION}.zip && \
mv opencv_contrib-${OPENCV_VERSION} opencv_contrib
# Build OpenCV
RUN cd opencv && mkdir build && cd build && \
cmake \
-D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_SHARED_LIBS=OFF \
-D ENABLE_CXX11=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_JAVA=OFF \
-D BUILD_opencv_app=OFF \
-D BUILD_opencv_java=OFF \
-D BUILD_opencv_python=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_opencv_js=OFF \
-D WITH_GSTREAMER=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
.. && make -j12 && make install && ldconfig
WORKDIR /
# Download OpenCvSharp
RUN git clone https://github.com/shimat/opencvsharp.git
RUN cd opencvsharp && git fetch --all --tags --prune
# Install the Extern lib.
WORKDIR /opencvsharp/src
RUN mkdir /opencvsharp/make
RUN cd /opencvsharp/make && cmake /opencvsharp/src && make -j12 && make install
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/share/opencv4/lib/:/usr/local/lib/:/lib/x86_64-linux-gnu/"
I have just re-checked, it builds and works fine (with the
If it still can't build the image (getting compilation error), I would recommend to "nuke" your docker by removing every container, image and volume you might have (of course, if there isn't anything valuable there): #!/usr/bin/env bash
docker rm -f -v $(docker ps -aq)
docker rmi -f $(docker images -q)
docker volume rm $(docker volume ls -q)
docker network rm $(docker network ls -q) |
Hi ArXen42, |
I have moved forward a little bit but I am still stuck: When I compile from Docker-Compose : When I compile from my web app project it runs and I can access it but I get the opencvsharpextern library missing. |
@Lerseb OpenCVSharpEnvironment is just a directory with Dockerfile that builds this image, didn't notice I included it and didn't mention. I wouldn't use cache_from some existing image - the whole purpose of docker-compose is to build your whole set of containers at once and guarantee that everything is in-sync. So, it will build opencvsharp_base image first, then it will build everything that depends on it. Regarding Visual Studio feature for adding docker support: it looked somewhat magical to me when I tried it for the first time myself. Regarding your issue - I will try to create sample repo soon. |
I can build the docker images provided on this page https://github.com/shimat/opencvsharp/blob/master/docker/ubuntu.18.04-x64/Dockerfile |
@Lerseb sorry for late response, forgot to check my github notifications, but here is example repo: You can clone it and run I recommend you to check if it works and compare your solution structure with this example. It may help to just create your project from scratch and copy-paste docker files ( |
Thank you @ArXen42. version: '3.4' services:
And my DockerfileWeb (the one building my web app) is FROM opencvsharp_base ENV ASPNETCORE_URLS http://+:80 WORKDIR /src EXPOSE 80 COPY ObserVisionWeb/ObserVisionWeb.csproj ObserVisionWeb/ RUN dotnet restore "ObserVisionWeb/ObserVisionWeb.csproj" --verbosity detailed COPY . . WORKDIR /src/ObserVisionWeb RUN dotnet build "ObserVisionWeb.csproj" -c Release -o /app/build --verbosity detailed WORKDIR /app ENTRYPOINT ["dotnet", "ObserVisionWeb.dll"] I would like to thank everybody who helped me troubleshouting this. |
Summary of your issue
Environment
Mac Osx 10.15.7
Visual Studio 2019 For Mac
Project is built in Docker container on local Mac using VS Docker compose feature.
installed packages
OpenCvSharp4 4.5.0 20201013
OpenCvSharp4.runtime.osx.10.15-64 4.5.0 20201013
Just installed in case it could help
OpenCvSharp4.runtime.debian.10-amd64 4.3.0 20200424
OpenCvSharp4.runtime.multi-arch 4.3.0 20200527
What did you do when you faced the problem?
The project (Aspnetcore web application) compile properly. It crashes when I pass the code below because OpenCvSharpExtern is missing.
var org = new Mat(image);
Example code:
Output:
What did you intend to be?
Inference on the provided image using my trained Yolo model (cfg, weights and names)
Image is provided in the attached files
The text was updated successfully, but these errors were encountered: