Skip to content

Build opencv-python-headless for alpine #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 of 4 tasks
a76yyyy opened this issue Jun 2, 2023 · 3 comments
Open
3 of 4 tasks

Build opencv-python-headless for alpine #854

a76yyyy opened this issue Jun 2, 2023 · 3 comments
Assignees

Comments

@a76yyyy
Copy link

a76yyyy commented Jun 2, 2023

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
@asmorkalov
Copy link
Collaborator

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.

@asmorkalov asmorkalov self-assigned this Jun 8, 2023
@sanmai-NL
Copy link

@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
Copy link
Author

a76yyyy commented Jul 6, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants