-
-
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
Simplify usage in different Linux environments #920
Comments
A bit better solution@shimat Thanks for the dockerfile you mentioned in #953. I modified this file to create base image that builds environment for running apps that use It can be added to Dockerized .NET project does not need any dependency aside from However, I'm yet to separate build environment from runtime here. To do so, one will need to copy OpenCV build output and libOpenCvSharp.so (these are currently installed directly into the container system using Guess that will be the next step but for now I don't mind a bit bloated container :) Dockerfile itself: FROM mcr.microsoft.com/dotnet/core/sdk:3.1-focal
ENV OPENCV_VERSION=4.3.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/" Example version: '3.4'
services:
opencvsharp_base:
image: opencvsharp_base
build:
context: OpenCVSharpEnvironment
some_image_processing_api:
restart: unless-stopped
build:
context: .
dockerfile: src/SomeImageProcessingApi/Dockerfile
args:
configuration: Debug
depends_on:
- opencvsharp_base Example FROM opencvsharp_base
WORKDIR /app
COPY /src/SomeImageProcessingApi/SomeImageProcessingApi.csproj ./src/SomeImageProcessingApi/
WORKDIR /app/src/SomeImageProcessingApi
RUN dotnet restore
WORKDIR /app
COPY /src/SomeImageProcessingApi/. ./src/SomeImageProcessingApi/
WORKDIR /app/src/SomeImageProcessingApi
ARG configuration
RUN dotnet publish -c $configuration -o out
# TODO: separate runtime container
WORKDIR /app/src/SomeImageProcessingApi/out
ENTRYPOINT ["dotnet", "SomeImageProcessingApi.dll"] |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I'm using mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic as runtimes image base (docker run -d -t image_id) then i execute docker exec container_name bash. The i follow the sample dockerfile step to install the depedencies and cmake. Unfortunately i face some error when build opencv
|
i also found the opencvsharp repo have dockerfile, i build from the dockerfile then will run into the error like this:
When i build from the opencvsharp repo's dockerfile, i make this "shimat/ubuntu18-dotnetcore3.1-opencv4.5.0:20201030" as runtime image base. |
now have another error is like this:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I'm going to write down issue, working-but-terrible solution and would like to ask more experienced people around here for better solution.
Issue
Linux binaries shipped with NuGet package are mostly unusable unless user have exactly the same environment as the one package was built in. Even if you install all the dependencies, you are most likely to end up with slightly different versions of your libraries and
OpenCVSharpExtern
won't work.So, unless you are using exactly the same Ubuntu with exactly the same versions of packages as on CI server, it won't work out of the box.
Working but problematic solution
Local environment
README.md
and buildOpenCvSharpExtern
.libOpenCvSharp
(without .so) and put file into/usr/lib
or make sureld
finds it some other way.Debug with
ldd
or just read exception (it will mention what dependency is missing) if you encounter problems.Docker
Things become even more fun here. If you are hosting ASP .NET Core app inside docker linux container, the only way I found is to build
OpenCvSharpExtern
in the container similar to production and then extract compilation result along with all dependencies.mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic
as runtime image base.docker exec container_name bash
to get into the container.apt-get install ...
, build OpenCV 4.3.0, build OpenCvSharp and make sure both are installed into the container system (present somewhere in/usr/local/share/opencvsharp4/
or elsewhere). There are CI scripts in this repo that should help withapt-get
part./usr/local
,/usr/lib
and/lib/x86_64-linux-gnu
which turned out to be 1.2GiB.docker-compose
automatically).Dockerfile
to copy these files from host onto runtime container after build.ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/share/opencv4/lib/:/usr/local/lib/:/lib/x86_64-linux-gnu/"
will probably be required.Questions
libOpenCvSharpExtern.so
to embed all the dependent libs into it? It looks like it was successfully done for Windows, so I wonder if it is possible on Linux.compiling OpenCV in production environment
steps on your CI server or there is better approach?I'm fairly noob in either docker and magic of C++ compilation, sorry if I'm missing something obvious.
Hope this helps someone or attracts answers with better solutions :)
The text was updated successfully, but these errors were encountered: