Skip to content

move cv2 install to python script and add as optional dependency #510

@eliteprox

Description

@eliteprox

ComfyStream provides it's own opencv build precompiled for nvidia gpu architectures.

When opencv installs into comfystream (docker only), the script removes any existing versions of opencv and replaces the installation with binaries in the PATH.

if [ "$1" = "--opencv-cuda" ]; then
cd /workspace/comfystream
conda activate comfystream
# Check if OpenCV CUDA build already exists
if [ ! -f "/workspace/comfystream/opencv-cuda-release.tar.gz" ]; then
# Download and extract OpenCV CUDA build
DOWNLOAD_NAME="opencv-cuda-release.tar.gz"
wget -q -O "$DOWNLOAD_NAME" https://github.com/JJassonn69/ComfyUI-Stream-Pack/releases/download/v2.1/opencv-cuda-release.tar.gz
tar -xzf "$DOWNLOAD_NAME" -C /workspace/comfystream/
rm "$DOWNLOAD_NAME"
else
echo "OpenCV CUDA build already exists, skipping download."
fi
# Install required libraries
# Remove existing cv2 package
SITE_PACKAGES_DIR="/workspace/miniconda3/envs/comfystream/lib/python3.12/site-packages"
rm -rf "${SITE_PACKAGES_DIR}/cv2"*
# Copy new cv2 package
cp -r /workspace/comfystream/cv2 "${SITE_PACKAGES_DIR}/"
# Handle library dependencies
CONDA_ENV_LIB="/workspace/miniconda3/envs/comfystream/lib"
# Remove existing libstdc++ and copy system one
rm -f "${CONDA_ENV_LIB}/libstdc++.so"*
cp /usr/lib/x86_64-linux-gnu/libstdc++.so* "${CONDA_ENV_LIB}/"
# Copy OpenCV libraries
cp /workspace/comfystream/opencv/build/lib/libopencv_* /usr/lib/x86_64-linux-gnu/
# remove the opencv-contrib and cv2 folders
rm -rf /workspace/comfystream/opencv_contrib
rm -rf /workspace/comfystream/cv2
echo "OpenCV CUDA installation completed"
shift
fi


This is not flexible enough for other applications that require a valid reference to cv2

  • ComfyUI-StreamPack needs this package for super resolution
  • PyTrickle would benefit from an opencv build with nvidia support

Ideally we can:

  • Modify the script so that it installs cv2 (opencv-cuda) using precompiled binaries defined in pyproject.toml to remove the docker dependency and support the customized opencv install in other applications
  • Consider publishing the precompiled wheels to pypip

Metadata

Metadata

Assignees

Labels

stream-packRelated to the ComfyUI Stream Pack custom nodes

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions