Skip to content

Instantly share code, notes, and snippets.

@cpatulea
Created December 15, 2024 02:45
Show Gist options
  • Save cpatulea/6da5c0b4f86eecb80cd92e14a055bd5e to your computer and use it in GitHub Desktop.
Save cpatulea/6da5c0b4f86eecb80cd92e14a055bd5e to your computer and use it in GitHub Desktop.
HomeAssistant with OpenCV
# Usage:
# docker build -t ghcr.io/home-assistant/home-assistant:local .
# docker run -d --name homeassistant --restart=always \
# --privileged -e TZ=America/Montreal \
# -v /opt/homeassistant:/config -v /run/dbus:/run/dbus:ro \
# --network=host \
# ghcr.io/home-assistant/home-assistant:local
# Can't build opencv directly in 'core' image, it lacks Ninja and GMake.
# "CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles"."
FROM ghcr.io/home-assistant/wheels/amd64/musllinux_1_2/cp313:dev AS wheels
# Workaround for
# https://github.com/home-assistant/core/issues/94617
# https://github.com/opencv/opencv-python/issues/988
RUN git clone --depth 1 -b 988-support-py3.12 https://github.com/bryankaplan/opencv-python.git
# https://github.com/home-assistant/core/blob/46db3964f3f35e2f7526b45c1d73056f81d03a99/.github/workflows/wheels.yml#L73
# Not sure if this is needed, got it working without, so keeping it disabled.
#ENV CI_BUILD=1
# 'headless' build seems broken: " /data/opencv-python/opencv/modules/python/src2/cv2.hpp:39:10: fatal error: numpy/ndarrayobject.h: No such file or directory"
#ENV ENABLE_HEADLESS=1
RUN cd opencv-python && MAKEFLAGS="-j$(nproc)" pip wheel -v .
FROM ghcr.io/home-assistant/home-assistant:stable
COPY --from=wheels /data/opencv-python/opencv_python-4.10.0+218a392-cp313-cp313-linux_x86_64.whl .
RUN pip install ./opencv_python-4.10.0+218a392-cp313-cp313-linux_x86_64.whl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment