Skip to content

Instantly share code, notes, and snippets.

@liviaerxin
Last active May 24, 2025 23:43
Show Gist options
  • Save liviaerxin/6ee3d4faea1614572e621d81d0e114c8 to your computer and use it in GitHub Desktop.
Save liviaerxin/6ee3d4faea1614572e621d81d0e114c8 to your computer and use it in GitHub Desktop.
Build OpenCV and Python Bindings in Mac(QT, Gstreamer Support)

Build OpenCV in Mac with QT, Gstreamer Support

Install dependencies

brew install cmake #
brew install qt5 #optional
brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav #optional
pip3 install numpy

Download OpenCV source code

git clone https://github.com/opencv/opencv.git
cd opencv
git checkout master
cd ..

git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout master
cd ..

Configure with require flags

mkdir build_opencv
cd build_opencv

QT5PATH=/Users/siyao/Qt/5.13.1/clang_64/ #optional
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D BUILD_opencv_python2=OFF \
    -D BUILD_opencv_python3=ONPf \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D PYTHON3_EXECUTABLE=$(which python3) \
    -D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
    -D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
    -D WITH_GSTREAMER=ON \ #optional
    -D WITH_OPENGL=ON \ #optional
    -D CMAKE_PREFIX_PATH=$QT5PATH \ #optional
    -D CMAKE_MODULE_PATH="$QT5PATH"/lib/cmake \ #optional
    -D BUILD_EXAMPLES=ON ../opencv #downloaded opencv source folder

Build and Install

make -j$(sysctl -n hw.physicalcpu)
make install

Test

python3 -c "import cv2; print(cv2.__version__)"

references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment