When it comes recognizing face but you realize the module is not in opencv, what to do? Cry? Maybe. I spent 1.2 days to figure out that the face module is not in that repository. Instead, it’s in opencv_contrib. Even worse, we can’t use Podfile to generate the framework to include a single module in opencv_contrib!

Not much blogs online have solution for that. So I’m writing what I figured out. Here’re the steps to manually add a single module in opencv_contrib to opencv2.framework:

  • Download opencv from https://github.com/opencv/opencv
  • Download opencv_contrib from https://github.com/opencv/opencv_contrib
  • Copy the face module in opencv_contrib (opencv_contrib/modules/face) to opencv’s modules folder (opencv/modules).
  • Build opencv2.framework [2]:
    1. Make symbolic link for Xcode to let OpenCV build scripts find the compiler, header files etc.
      cd /
      sudo ln -s /Applications/Xcode.app/Contents/Developer Developer
    2. Build opencv2.framework
      cd ~/
      python opencv/platforms/ios/build_framework.py ios
  • If everything works, a few minutes later you will get ~//ios/opencv2.framework. You can add this framework to your Xcode projects [2].
  • Add the following builtin frameworks to the project because opencv2.framework is dependent on those:
    • AssetsLibrary.framework
    • CoreMedia.framework
    • AVFoundation.framework
  • Done! Now you can compile and run the project with face recognition included!


[1] Integrating armco in opencv_contrib into opencv2.framework. https://github.com/opencv/opencv/issues/6530.

[2] Installation in iOS. http://docs.opencv.org/2.4/doc/tutorials/introduction/ios_install/ios_install.html#ios-installation.