opencv / opencv-python

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
https://pypi.org/project/opencv-python/
MIT License
4.56k stars 852 forks source link

Build opencv-python-headless for alpine #854

Open a76yyyy opened 1 year ago

a76yyyy commented 1 year ago

Expected behaviour

In alpine pkg, I can only search for the complete build package of py3-opencv.

Hope to provide headless build package.

My dockerfile for reference

FROM alpine:edge

ARG TARGETARCH
# ENV TARGETARCH=${TARGETARCH}
# ENV ENABLE_HEADLESS=1

# Install packages
RUN echo 'https://mirrors.ustc.edu.cn/alpine/edge/testing' >> /etc/apk/repositories && \
    apk update && \
    apk add --update --no-cache bash git tzdata ca-certificates file python3 py3-six && \
    # ln -s /usr/bin/python3 /usr/bin/python && \
    [[ "${TARGETARCH}" != "i386" ]] && [[ "${TARGETARCH}" != "s390x" ]] && { \
    apk add --update --no-cache py3-pillow py3-numpy \
    libjpeg libpng tiff libwebp openjpeg openjpeg-tools eigen blas libtbb && \
    apk add --update --no-cache --virtual .build_deps py3-pip py3-setuptools py3-wheel protobuf-dev py3-numpy-dev \
        clang cmake lld samurai build-base gcc python3-dev musl-dev libffi-dev g++ linux-headers make libva-glx-dev \
        openblas-dev libjpeg-turbo-dev libpng-dev tiff-dev libwebp-dev openjpeg-dev libtbb-dev eigen-dev blas-dev && \
    mkdir opencv && cd opencv && \
    git clone https://github.com/opencv/opencv.git && \
    [[ "${TARGETARCH}" == "amd64" ]] && \
        extra_cmake_flags="-D CPU_BASELINE_DISABLE=SSE3 -D CPU_BASELINE_REQUIRE=SSE2" || extra_cmake_flags="" && \
    export ENABLE_HEADLESS=1 && \
    CC=clang CXX=clang++ \
    cmake -B build -G Ninja \
        -D CMAKE_BUILD_TYPE=RELEASE \
        -D CMAKE_INSTALL_PREFIX=/usr \
        -D CMAKE_INSTALL_LIBDIR=lib \
        -D CMAKE_SKIP_INSTALL_RPATH=ON \
        -D ENABLE_BUILD_HARDENING=ON \
        -D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
        -D OPENCV_ENABLE_NONFREE=OFF \
        -D OPENCV_SKIP_PYTHON_LOADER=ON \
        -D OPENCV_GENERATE_SETUPVARS=OFF \
        -D WITH_JPEG=ON \
        -D WITH_PNG=ON \
        -D WITH_TIFF=ON \
        -D WITH_WEBP=ON \
        -D WITH_JASPER=ON \
        -D WITH_EIGEN=ON \
        -D WITH_TBB=ON \
        -D WITH_LAPACK=ON \
        -D WITH_PROTOBUF=ON \
        -D WITH_ADE=OFF \
        -D WITH_V4L=OFF \
        -D WITH_GSTREAMER=OFF \
        -D WITH_GTK=OFF \
        -D WITH_QT=OFF \
        -D WITH_CUDA=OFF \
        -D WITH_VTK=OFF \
        -D WITH_OPENEXR=OFF \
        -D WITH_FFMPEG=OFF \
        -D WITH_OPENCL=OFF \
        -D WITH_OPENNI=OFF \
        -D WITH_XINE=OFF \
        -D WITH_GDAL=OFF \
        -D WITH_IPP=OFF \
        -D WITH_opencv_gapi=OFF \
        -D WITH_IPP=OFF \
        -D BUILD_OPENCV_PYTHON3=ON \
        -D BUILD_OPENCV_PYTHON2=OFF \
        -D BUILD_OPENCV_JAVA=OFF \
        -D BUILD_TESTS=OFF \
        -D BUILD_IPP_IW=OFF \
        -D BUILD_PERF_TESTS=OFF \
        -D BUILD_EXAMPLES=OFF \
        -D BUILD_ANDROID_EXAMPLES=OFF \
        -D BUILD_DOCS=OFF \
        -D BUILD_ITT=OFF \
        -D INSTALL_PYTHON_EXAMPLES=OFF \
        -D INSTALL_C_EXAMPLES=OFF \
        -D INSTALL_TESTS=OFF \
        -D PYTHON3_EXECUTABLE=/usr/bin/python3 \
        -D PYTHON3_INCLUDE_DIR=$(python -c "from sysconfig import get_paths as gp; print(gp()['include'])") \
        -D PYTHON3_LIBRARY=/usr/lib/libpython3.so \
        -D PYTHON3_PACKAGES_PATH=$(python -c "from sysconfig import get_paths as gp; print(gp()['purelib'])") \
        -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python -c "from sysconfig import get_paths as gp; print(gp()['purelib'])")/numpy/core/include/ \
        -D Protobuf_INCLUDE_DIR=/usr/include/google/protobuf \
        -D Protobuf_LIBRARY=/usr/lib/libprotobuf.so \
        -D Protobuf_PROTOC_EXECUTABLE=/usr/bin/protoc \
        $extra_cmake_flags \
        ./opencv \
    && cmake --build build && \
    cmake --install build && \
    cd / && rm -rf /opencv && \
    apk del .build_deps; \
    } || { \
    apk add --update --no-cache libprotobuf-lite && \
    echo "Opencv Builder does not currently support building i386 and s390x wheels";} && \
    rm -rf /var/cache/apk/* && \
    rm -rf /usr/share/man/*
Issue submission checklist
asmorkalov commented 1 year ago

The mentioned Alpine package is built by Alpine team, but not OpenCV. So we cannot affect on it. OpenCV team is looking on options besides manylinux2014 environment for Linux, but it's not a question for the next 4.8 release.

sanmai-NL commented 1 year ago

@a76yyyy Can you host this Dockerfile under version control for the time being? I have some tweaks, and @asmorkalov suggests this won't be solved too soon.

a76yyyy commented 1 year ago

@a76yyyy Can you host this Dockerfile under version control for the time being? I have some tweaks, and @asmorkalov suggests this won't be solved too soon.

I don't actually write alpine pkg build scripts, so you can use my FYI DockerFile for anything