Posts from the “OpenCV” Category

Add Face Module to opencv2.framework

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 say that. So I’m recording. Here’re the steps to manually add a single module in opencv_contrib to opencv2.framework:

  • Download opencv from
  • Download opencv_contrib from
  • 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/ Developer
    2. Build opencv2.framework
      cd ~/
      python opencv/platforms/ios/ ios
  • If everything’s fine, 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.

[2] Installation in iOS.

Generate Samples from Image Sequence by Distortion

Option 1 – Same distortion for all positive samples

  • Create samples from each sample from a folder:
    • for imagefile in /*.jpg; do imagename=`basename $imagefile`; opencv_createsamples -img $imagefile -num  -bg  -vec /$imagename.vec -w  -h ; done
  • Merge the vec files:
    • Download `` from
    • Navigate to `` in your terminal and enter:
      python -v your_vec_directory -o your_output_filename.vec

Option 2 – Random distortion for each positive sample