opencv / opencv/opencv-python

Build opencv-python-headless for alpine

Open
#854 3 comments 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Description

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
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.