Bitmap Smart Clipping using OpenCV

Introduction: 图片智能裁剪保留重要部分显示
Other: 利用淘宝的 http://code.taobao.org/p/tclip/ 库完成
一淘玩客正在使用的图片裁剪,自动识别图片中的重要区域,并且在图片裁剪时保留重要区域
特点:(1). 能进行人脸识别。图片中有人脸,将自动视为人脸区域为重要区域,将不会被裁剪掉
(2).自动其它重要区域。如果图片中未识别出人脸,则会根据特征分布计算出重区域
More: Author   ReportBugs   
Tags:

based on http://code.taobao.org/p/tclip/

recommend iOS version: https://github.com/croath/UIImageView-BetterFace

Demo Screenshots

demo screenshots

Features

  • using OpenCV to detect faces firstly, if have faces, won't cut faces off
  • using OpenCV to detect other characters secondly, if found significant zone, won't cut it off
  • using FAST feature detector instead of SURF, thanks for @yanunon

Usage

  • copy config file to app dir

      String configPath = TClip.copyConfig(context, TClip.CONFIG, R.raw.haarcascade_frontalface_alt);
    
  • get cropped bitmap

      //config: /data/data/com.demo.tclip.debug/haarcascade_frontalface_alt.xml
      Bitmap ret = TClip.crop(configPath, sourceBitmap, width, height);
    

Build

  • download OpenCV & unzip to /home/user/opencv-android-sdk
  • export OPENCV_PACKAGE_DIR="/home/user/opencv-android-sdk"
  • libnonfree.so & libopencv_java.so from beartung/nonfree-opencv-android
  • using FAST feature detector without libnonfree
  • cd jni && ndk-build
Apps
About Me
GitHub: Trinea
Facebook: Dev Tools