This is a short post mainly for my reference on how to run OpenCV on OSX to detect faces from a Logitech HD Pro Webcam C920. Note, the below assumes Python 3.7 is already installed.
The first step is to install the xcode command line develop tools, ffmpeg, and cmake.
brew install ffmpeg
brew install cmake
Next, install numpy using pip.
pip3.7 install numpy
Pull down the OpenCV source from GitHub.
git clone https://github.com/opencv/opencv.git
Finally, build and install from source.
cmake -DPYTHON_DEFAULT_EXECUTABLE=python3.7 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_opencv_python2=False -DBUILD_opencv_python3=True -DPYTHON3_EXECUTABLE=python3.7 –FFMPEG_INCLUDE_DIR=/usr/local/Cellar/ffmpeg/4.1.3_1/include/ FFMPEG_LIB_DIR=/usr/local/Cellar/ffmpeg/4.1.3_1/lib/ ../
sudo make install
Confirm OpenCV is installed successfully and print the version.
python3.7 -c “import cv2; print(cv2.__version__)”
Finally the code (for reference, GitHub repository is here)