-
Notifications
You must be signed in to change notification settings - Fork 875
/
Copy pathDockerfile.opencv-static-alpine
193 lines (171 loc) · 5.5 KB
/
Dockerfile.opencv-static-alpine
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# syntax=docker/dockerfile:1.3
# To build release:
# docker buildx build -f Dockerfile.opencv-static-alpine -t ghcr.io/hybridgroup/opencv:4.11-alpine --platform=linux/arm64,linux/amd64 --load .
# linux/amd64 build
FROM --platform=linux/amd64 ghcr.io/hybridgroup/gstreamer:1.24-alpine AS gstreamer-amd64
# Stage 1: Build OpenCV
FROM --platform=linux/amd64 ghcr.io/hybridgroup/ffmpeg:5.16-alpine AS builder-amd64
# Set OpenCV version
ARG OPENCV_VERSION=4.11.0
# Download OpenCV source code
WORKDIR /opencv
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
unzip -q opencv.zip && \
mv opencv-${OPENCV_VERSION} opencv
WORKDIR /opencv_contrib
RUN wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
unzip -q opencv_contrib.zip && \
mv opencv_contrib-${OPENCV_VERSION} opencv_contrib
# Install dependencies
RUN apk update && apk add --no-cache \
build-base \
cmake \
git \
diffutils \
perl \
wget \
unzip \
pkgconfig \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev openssl \
libxml2-dev \
bison \
flex \
glib-dev \
gobject-introspection-dev \
libcap-dev \
libcap-utils \
meson
# copy gstreamer
COPY --from=gstreamer-amd64 /gstbin/lib /usr/local/lib
COPY --from=gstreamer-amd64 /gstbin/include/gstreamer-1.0/gst /usr/local/include/gst
# Build OpenCV
WORKDIR /opencv/opencv/build
RUN cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_IPP=ON \
-D BUILD_WITH_DYNAMIC_IPP=OFF \
-D BUILD_IPP_IW=ON \
-D WITH_OPENGL=ON \
-D BUILD_OPENGL=ON \
-D WITH_QT=OFF \
-D WITH_FREETYPE=OFF \
-D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib/opencv_contrib/modules \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_SHARED_LIBS=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D WITH_SIMD=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D WITH_WEBP=ON \
-D BUILD_WEBP=ON \
-D WITH_OPENJPEG=ON \
-D BUILD_OPENJPEG=ON \
-D BUILD_TIFF=ON \
-D BUILD_PNG=ON \
-D BUILD_ZLIB=ON \
-D BUILD_JPEG=ON \
-D WITH_SIMD=ON \
-D ENABLE_LIBJPEG_TURBO_SIMD=OFF \
-D BUILD_opencv_java=NO \
-D BUILD_opencv_python=NO \
-D BUILD_opencv_python2=NO \
-D BUILD_opencv_python3=NO \
.. && \
make -j$(nproc) && \
make install
# linux/arm64 build
FROM --platform=linux/arm64 ghcr.io/hybridgroup/gstreamer:1.24-alpine AS gstreamer-arm64
FROM --platform=linux/arm64 ghcr.io/hybridgroup/ffmpeg:5.16-alpine AS builder-arm64
# Set OpenCV version
ARG OPENCV_VERSION=4.11.0
# Download OpenCV source code
WORKDIR /opencv
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
unzip -q opencv.zip && \
mv opencv-${OPENCV_VERSION} opencv
WORKDIR /opencv_contrib
RUN wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
unzip -q opencv_contrib.zip && \
mv opencv_contrib-${OPENCV_VERSION} opencv_contrib
# Install dependencies
RUN apk update && apk add --no-cache \
build-base \
cmake \
git \
diffutils \
perl \
wget \
unzip \
pkgconfig \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev openssl \
libxml2-dev \
bison \
flex \
glib-dev \
gobject-introspection-dev \
libcap-dev \
libcap-utils \
meson
# copy gstreamer
COPY --from=gstreamer-arm64 /gstbin/lib /usr/local/lib
COPY --from=gstreamer-arm64 /gstbin/include/gstreamer-1.0/gst /usr/local/include/gst
# Build OpenCV
WORKDIR /opencv/opencv/build
RUN cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_IPP=OFF \
-D ENABLE_NEON=ON \
-D WITH_OPENGL=ON \
-D BUILD_OPENGL=ON \
-D WITH_QT=OFF \
-D WITH_FREETYPE=OFF \
-D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib/opencv_contrib/modules \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_SHARED_LIBS=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D WITH_SIMD=ON \
-D ENABLE_LIBJPEG_TURBO_SIMD=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D WITH_WEBP=ON \
-D BUILD_WEBP=ON \
-D WITH_OPENJPEG=ON \
-D BUILD_OPENJPEG=ON \
-D BUILD_TIFF=ON \
-D BUILD_PNG=ON \
-D BUILD_ZLIB=ON \
-D BUILD_JPEG=ON \
-D WITH_SIMD=ON \
-D ENABLE_LIBJPEG_TURBO_SIMD=OFF \
-D BUILD_opencv_java=NO \
-D BUILD_opencv_python=NO \
-D BUILD_opencv_python2=NO \
-D BUILD_opencv_python3=NO \
.. && \
make -j$(nproc) && \
make install
# Stage 2: Create final image
FROM builder-${TARGETARCH} AS final
# Set environment variables
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/opencv4/3rdparty:${LD_LIBRARY_PATH}
CMD ["opencv_version", "-b"]