Created
June 7, 2021 01:30
-
-
Save agurtovoy/ddec1b9157be6832633daef3826d9f00 to your computer and use it in GitHub Desktop.
Docker build image for OpenCV running in AWS Lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# build OpenCV | |
FROM public.ecr.aws/lambda/python:3.8 | |
# install prerequisites | |
RUN yum update -y && yum install -y wget tar binutils make | |
RUN yum install -y cmake3 && ln -s /usr/bin/cmake3 /usr/bin/cmake | |
RUN yum install -y ninja-build && ln -s /usr/bin/ninja-build /usr/bin/ninja | |
RUN yum install -y gcc10 gcc10-c++ && ln -s /usr/bin/gcc10-gcc /usr/bin/gcc && ln -s /usr/bin/gcc10-c++ /usr/bin/g++ | |
# building from sources, see https://docs.opencv.org/3.4/dd/dd5/tutorial_py_setup_in_fedora.html | |
RUN yum install -y python-devel numpy gtk2-devel libdc1394-devel libv4l-devel ffmpeg-devel gstreamer-plugins-base-devel && \ | |
yum install -y libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel eigen3-devel | |
# install a more recent version of Intel TBB than tbb-devel | |
COPY ./Intel-oneAPI.repo /etc/yum.repos.d | |
RUN yum install -y intel-oneapi-common-vars-2021.1.1 && \ | |
yum install -y intel-oneapi-tbb-devel-2021.1.1 | |
WORKDIR /usr/src/ | |
ARG OPENCV_VERSION=4.5.1 | |
ARG OPENCV_RELEASE=opencv-$OPENCV_VERSION | |
RUN wget -O $OPENCV_RELEASE.tar.gz https://github.com/opencv/opencv/archive/refs/tags/$OPENCV_VERSION.tar.gz && \ | |
tar xzf $OPENCV_RELEASE.tar.gz | |
WORKDIR /usr/src/$OPENCV_RELEASE | |
RUN mkdir build | |
WORKDIR /usr/src/$OPENCV_RELEASE/build | |
RUN cmake -D PYTHON_DEFAULT_EXECUTABLE=$(which python) \ | |
-D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv \ | |
-D WITH_TBB=ON -D WITH_EIGEN=ON BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF \ | |
-D WITH_OPENCL=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF \ | |
-D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF \ | |
-D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF \ | |
-D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF .. | |
# build with just a single process using make; building in parallel either make -jN or ninja fails with | |
# "g++: fatal error: Killed signal terminated program cc1plus" — according to the internet, due to not enough RAM | |
RUN make | |
RUN make install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment