Skip to content

Instantly share code, notes, and snippets.

@bofish
Last active November 15, 2018 15:39
Show Gist options
  • Save bofish/c46f98c4b9e87cc0e392fbe5c1425d54 to your computer and use it in GitHub Desktop.
Save bofish/c46f98c4b9e87cc0e392fbe5c1425d54 to your computer and use it in GitHub Desktop.
Debian with python 3.7 + openCV 3.4 + vscode
# $ docker build -t py-opencv Dockerfile
# $ docker run -ti --rm \
# -e DISPLAY=$DISPLAY \
# -v /tmp/.X11-unix:/tmp/.X11-unix \
# -v /data:/data_docker \
# py-opencv
# The part of Opencv setting base on jjanzic/docker-python3-opencv:contrib
FROM python:3.7
# Initial
RUN apt-get update && \
apt-get install -y \
locales \
locales-all \
build-essential \
cmake \
git \
wget \
unzip \
yasm \
pkg-config \
libswscale-dev \
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libavformat-dev \
libpq-dev \
dbus \
libavcodec-dev \
# libjasper-dev \
libdc1394-22-dev \
libv4l-dev \
libgtk2.0-dev \
libdbus-1-dev \
libxml2-dev \
libxvidcore-dev \
libgtk-3-dev \
libx264-dev\
libatlas-base-dev \
gfortran \
dbus-x11 \
libcanberra-gtk-module \
libcanberra-gtk3-module \
libxss1 \
sudo
# Install openCV
RUN pip install numpy scipy matplotlib pyyaml numba
WORKDIR /
RUN mkdir /tempFile && cd /tempFile \
&& git clone https://github.com/opencv/opencv.git \
&& git clone https://github.com/opencv/opencv_contrib.git \
&& mkdir /tempFile/opencv/build \
&& cd /tempFile/opencv/build \
&& cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON_EXECUTABLE=$(which python3.7) \
-D OPENCV_EXTRA_MODULES_PATH=/tempFile/opencv_contrib/modules \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D BUILD_EXAMPLES=ON \
-D OPENCV_ENABLE_NONFREE=ON \
.. \
&& make -j7 \
&& make install \
&& rm -r /tempFile
# install vscode
RUN apt-get install -y curl \
&& curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
&& install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/ \
&& sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' \
&& apt-get install -y apt-transport-https \
&& apt-get update \
&& apt-get install -y code \
&& rm microsoft.gpg
# Add Font
WORKDIR /
RUN mkdir /fontTemp && cd /fontTemp \
&& wget -O sfmono.zip https://github.com/bofish/SFMono_Font/archive/master.zip \
&& unzip sfmono.zip \
&& mkdir /usr/share/fonts/sfmono \
&& mv SFMono_Font-master/* /usr/share/fonts/sfmono \
&& fc-cache -fv \
&& rm -r /fontTemp/
RUN useradd --create-home benson -s /bin/bash && usermod -aG sudo benson
# passwd USERNAME # change password manually
RUN printf '# GTK and X11 setting\nexport QT_X11_NO_MITSHM=1\nexport LANGUAGE=en_US.UTF-8\nexport LC_ALL=en_US.UTF-8\nexport LANG=en_US.UTF-8\nexport LC_TYPE=en_US.UTF-8\nexport NO_AT_BRIDGE=1' >> /home/benson/.profile
CMD bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment