Python2 (opencv2) with Homebrew

Python 2

  • brew install python
  • brew install opencv
  • python
>>> import cv2

Python3 (opencv3) with Homebrew and PIP

Python3

  • brew install python3
  • brew uninstall opencv3
  • brew install opencv3 --without-python --with-python3
  • echo /usr/local/opt/opencv3/lib/python3.6/site-packages >> /usr/local/lib/python3.6/site-packages/opencv3.pth
  • python3
>>> import cv2

Refer to this

Install dlib (only for Python3)

dlib is very useful for face detection machine learning, but it is hard to install on mac osx with python. compile issue and compile issue2

I got some script from this, but still not working for me.

How to install dlib HEAD (w/ python bindings) from github

These instructions assume you are on macOS, but basically the same on Linux.

Pre-reqs:

  • Have Python 3 installed. On macOS, this could be installed from homebrew or even via standard Python 3.6 downloaded installer from https://www.python.org/download. On Linux, just use your package manager.
  • On macOS:
    • Install XCode from the Mac App Store (or install the XCode command line utils).
    • Have homebrew installed
    • Install boost with this command: brew install boost-python --with-python3 --without-python
  • On Linux:
    • Install boost. On Ubuntu, that's sudo apt-get install libboost-all-dev
  • This assumes you don't have an nVidia GPU and don't have Cuda and cuDNN installed and don't want GPU acceleration (since none of the current Mac models support this).

Clone the code from github:

git clone https://github.com/davisking/dlib.git

Build the main dlib library:

cd dlib
mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build .

Build and install the Python extensions:

cd ..
python3 setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA

At this point, you should be able to run python3 and type import dlib successfully.

view raw dlib_install.md hosted with ❤ by GitHub

Using PIP3 to install dlib for python3

  • Install boost for python3 but not for python2
    • brew install boost-python --with-python3 --without-python
  • pip3 install dlib
  • python3
>>> import dlib

Reference


Buy Me A Coffee

Evan

Attitude is everything