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 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’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!

References

[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.

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 `mergevec.py` from https://github.com/wulfebw/mergevec
    • Navigate to `mergevec.py` in your terminal and enter:
      python mergevec.py -v your_vec_directory -o your_output_filename.vec

Option 2 – Random distortion for each positive sample

https://github.com/mrnugget/opencv-haar-classifier-training