0

I'm currently trying to run an application using Docker but get the following error message when I start the application:

 error while loading shared libraries: libopencv_highgui.so.4.4: cannot open shared object file: No such file or directory

I assume that something is going wrong in the docker file and that the installation is not complete or correct. Therefore I have added the section about OpenCV at the end of the post. Did I miss an important step or an error in the dockerfile?

FROM nvidia/cuda:10.2-devel-ubuntu18.04 as TOOLKITS
RUN apt-get update && apt-get install -y apt-utils
# Install additional packages
RUN apt-get install -y \
    build-essential \
    bzip2 \
    checkinstall \
    cmake \
    curl \
    gcc \
    gfortran \
    git \
    pkg-config \
    python3-pip \
    python3-dev \
    python3-numpy \
    nano \ 
    openexr \
    unzip \
    wget \
    yasm


FROM TOOLKITS as GIT_PULLS
WORKDIR /
RUN git clone https://github.com/opencv/opencv.git
RUN git clone https://github.com/opencv/opencv_contrib.git

FROM GIT_PULLS as OPENCV_PREPERATION
RUN apt-get install -y \
    libgtk-3-dev \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    libv4l-dev \
    libxvidcore-dev \
    libx264-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    libatlas-base-dev \
    libtbb2 \
    libtbb-dev \
    libdc1394-22-dev


FROM OPENCV_PREPERATION as OPENCV_CMAKE
WORKDIR /
RUN mkdir /opencv/build
WORKDIR /opencv/build
RUN cmake \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DWITH_TBB=ON \
-DWITH_V4L=ON \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DWITH_OPENGL=ON \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DOPENCV_PC_FILE_NAME=opencv.pc \
-DBUILD_EXAMPLES=ON ..

FROM OPENCV_CMAKE as BUILD_OPENCV_MAKE
RUN make -j $(nproc)
RUN make install

FROM TOOLKITS 
COPY --from=XXX /opencv /opencv
COPY --from=XXX /opencv_contrib /opencv_contrib

Omer Tuchfeld
  • 2,886
  • 1
  • 17
  • 24
john-mueller
  • 107
  • 2
  • 9
  • What's "TOOLKITS"? If you could please provide a Dockerfile that can be reproduced on other machines, helping you would be easier – Omer Tuchfeld Aug 13 '20 at 15:05
  • @Omer The docker file is relatively large and extensive. I have added the necessary dependencies for openCV here. The whole Dockerfile can be published as well but probably too confusing and not very helpful for troubleshooting. – john-mueller Aug 13 '20 at 15:08

3 Answers3

0

I was facing the same issue before when installing OpenCV in Docker with Python image. You probably don't need this much dependencies but it's an option. I will have a lightweight version that fits my case. Please give a try for the following code:

Heavy-loaded version:

FROM python:3.7

RUN apt-get update \
    && apt-get install -y \
        build-essential \
        cmake \
        git \
        wget \
        unzip \
        yasm \
        pkg-config \
        libswscale-dev \
        libtbb2 \
        libtbb-dev \
        libjpeg-dev \
        libpng-dev \
        libtiff-dev \
        libavformat-dev \
        libpq-dev \
    && rm -rf /var/lib/apt/lists/*

RUN pip install numpy

WORKDIR /
ENV OPENCV_VERSION="4.1.1"
# install opencv-python from its source 
RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip \
&& unzip ${OPENCV_VERSION}.zip \
&& mkdir /opencv-${OPENCV_VERSION}/cmake_binary \
&& cd /opencv-${OPENCV_VERSION}/cmake_binary \
&& cmake -DBUILD_TIFF=ON \
  -DBUILD_opencv_java=OFF \
  -DWITH_CUDA=OFF \
  -DWITH_OPENGL=ON \
  -DWITH_OPENCL=ON \
  -DWITH_IPP=ON \
  -DWITH_TBB=ON \
  -DWITH_EIGEN=ON \
  -DWITH_V4L=ON \
  -DBUILD_TESTS=OFF \
  -DBUILD_PERF_TESTS=OFF \
  -DCMAKE_BUILD_TYPE=RELEASE \
  -DCMAKE_INSTALL_PREFIX=$(python3.7 -c "import sys; print(sys.prefix)") \
  -DPYTHON_EXECUTABLE=$(which python3.7) \
  -DPYTHON_INCLUDE_DIR=$(python3.7 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
  -DPYTHON_PACKAGES_PATH=$(python3.7 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
  .. \
&& make install \
&& rm /${OPENCV_VERSION}.zip \
&& rm -r /opencv-${OPENCV_VERSION}
RUN ln -s \
  /usr/local/python/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so \
  /usr/local/lib/python3.7/site-packages/cv2.so
RUN apt-get --fix-missing update && apt-get --fix-broken install && apt-get install -y poppler-utils && apt-get install -y tesseract-ocr && \
    apt-get install -y libtesseract-dev && apt-get install -y libleptonica-dev && ldconfig && apt install -y libsm6 libxext6 && apt install -y python-opencv

Lightweight version:

FROM python:3.7 
RUN apt-get update -y 
RUN apt-update && apt install -y libsm6 libxext6 

For my case, I ended up using the heavy-loaded version just to save some hassle and both versions should work fine. For your reference, please also see this link and thanks to Neo Anderson's great help.

liamsuma
  • 156
  • 4
  • 19
0

I also had lots of issues in this process, and found this repository: https://github.com/janza/docker-python3-opencv Clone or download this and add the additional dependencies and files according to your requirement.

RusJaI
  • 666
  • 1
  • 7
  • 28
-2
apt-get update -y
apt install -y libsm6 libxext6
apt update
pip install pyglview
apt install -y libgl1-mesa-glx
shreyasm-dev
  • 2,711
  • 5
  • 16
  • 34