-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.android
146 lines (139 loc) · 4.65 KB
/
Dockerfile.android
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# From https://hub.docker.com/r/valian/docker-python-opencv-ffmpeg
# with the version changed to 3.4.5 (rather than 3.4.2)
#
# https://www.learnopencv.com/install-opencv3-on-ubuntu/
FROM ubuntu:16.04
LABEL maintainer "[email protected]"
ENV OPENCV_VERSION 3.4.5
# Necessary for tzdata, which wants to know the timezone
ENV DEBIAN_FRONTEND noninteractive
# Install all dependencies for OpenCV
RUN apt-get -y update && \
apt-get -y install --no-install-recommends \
python3 \
python3-dev \
git \
wget \
unzip \
cmake \
build-essential \
pkg-config \
libatlas-base-dev \
gfortran \
libjasper-dev \
libgtk2.0-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libjasper-dev \
libv4l-dev \
openjdk-8-jdk \
expect \
tzdata \
ninja-build \
ant \
&& \
# install python dependencies
wget https://bootstrap.pypa.io/get-pip.py && \
python3 get-pip.py && \
rm get-pip.py && \
pip3 install numpy \
&& \
# Install OpenCV
wget https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip -O opencv3.zip && \
unzip -q opencv3.zip && \
mv /opencv-$OPENCV_VERSION /opencv && \
rm opencv3.zip && \
wget https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip -O opencv_contrib3.zip && \
unzip -q opencv_contrib3.zip && \
mv /opencv_contrib-$OPENCV_VERSION /opencv_contrib && \
rm opencv_contrib3.zip &&\
# clean as much as possible
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Prepare opencv build
RUN mkdir /opencv/build && cd /opencv/build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_PYTHON_SUPPORT=ON \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules \
-D BUILD_EXAMPLES=OFF \
-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
-D WITH_IPP=OFF \
-D WITH_FFMPEG=ON \
-D WITH_V4L=ON ..
# make and Install opencv
RUN cd /opencv/build && \
make -j$(nproc) && \
make install && \
ldconfig && \
rm -rf /opencv/build
# Set correct gcc version
RUN apt-get -y update && \
apt-get install --no-install-recommends -y software-properties-common && \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get -y update && \
apt-get install -y gcc-7 g++-7 && \
rm /usr/bin/gcc /usr/bin/g++ && \
ln -s /usr/bin/gcc-7 /usr/bin/gcc && \
ln -s /usr/bin/g++-7 /usr/bin/g++ && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
\
# Get the tools that will get the Android SDK
mkdir /android_sdk && \
cd /android_sdk && \
wget https://dl.google.com/android/repository/tools_r25.2.5-linux.zip && \
unzip tools_r25.2.5-linux.zip && \
rm -rf tools_r25.2.5-linux.zip && \
\
# Get the actual sdk and build tools of the appropriate version
sh -c "/bin/echo -e 'y' | /android_sdk/tools/bin/sdkmanager --verbose 'build-tools;27.0.3'" && \
sh -c "/bin/echo -e 'y' | /android_sdk/tools/bin/sdkmanager --verbose 'platforms;android-26'" && \
sh -c "/bin/echo -e 'y' | /android_sdk/tools/bin/sdkmanager --verbose 'platform-tools'" && \
\
# Get the native development kit
mkdir /android_ndk && \
cd /android_ndk && \
wget https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip &&\
unzip android-ndk-r14b-linux-x86_64.zip && \
rm -rf android-ndk-r14b-linux-x86_64.zip && \
\
# Build the OpenCV Android SDK
mkdir /OpenCV-android-sdk && \
cd /OpenCV-android-sdk && \
python /opencv/platforms/android/build_sdk.py --ndk_path=/android_ndk/android-ndk-r14b --sdk_path=/android_sdk --no_ccache --extra_modules_path=/opencv_contrib/modules/ --config=/opencv/platforms/android/ndk-16.config.py --force_copy --force_opencv_toolchain && \
# Clean Opencv Android SDK Build
cd /OpenCV-android-sdk && \
mv OpenCV-android-sdk ~/ && \
rm -rf /OpenCV-android-sdk && \
\
# Clean as much as possible
apt-get -y remove \
python3-dev \
libatlas-base-dev \
gfortran \
libjasper-dev \
libgtk2.0-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libjasper-dev \
libv4l-dev \
ninja-build \
ant \
&& \
apt-get clean && \
rm -rf /opencv /opencv_contrib /var/lib/apt/lists/*
# Define default command.
CMD ["python3 --version"]