Giter VIP home page Giter VIP logo

face_roi's Introduction

FaceROI

A simple Ruby Gem to calculate an ROI in an image by indetifying faces using [OpenCV] (http://opencv.org/). This can be used to create optimal crops of images.

Adapted from and inspired by [paperclip-facecrop] (https://github.com/dagi3d/paperclip-facecrop).

Installation

Install OpenCV (Mac OSX)

$ sudo port install cmake # in case cmake has not already been installed

$ tar xvzf OpenCV-2.4.0.tar.bz2
$ cd OpenCV-2.4.0
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make
$ sudo make install

For other platforms: [Install Guide] (http://docs.opencv.org/doc/tutorials/introduction/table_of_content_introduction/table_of_content_introduction.html)

Install [Ruby OpenCV] (https://github.com/ruby-opencv/ruby-opencv/)

$ gem install ruby-opencv -- --with-opencv-dir=/usr/local

Install face_ROI

Add this line to your application's Gemfile:

gem 'face_ROI'

And then execute:

$ bundle

Or install it yourself as:

$ gem install face_ROI

Usage

Set path of OpenCV base directory

module FaceROI
  OPENCV_BASE= '/usr/local'
end

Sample usage

require 'face_ROI'

path='test/IMG_0465.jpg'
f=FaceROI::Finder.new(path, FaceROI::CONFIG1)

# In case there were no faces detected it will return the full image
roi_x, roi_y, roi_width, roi_height= f.roi
puts "(#{path}) has ROI?: #{f.has_roi?}"
puts "ROI Offset (#{roi_x}, #{roi_y}), width: #{roi_width}, height #{roi_height}"

# Save image for debugging purposes
image=f.image_with_faces
image.save('test/IMG_0465-with-faces.jpg')

Config help

From face_ROI/sample_config

  # Most optimal configuration, computation intensive, low chances of false positive
  CONFIG1= {
    :face => %w(haarcascade_frontalface_alt_tree.xml haarcascade_frontalface_alt.xml
    haarcascade_profileface.xml).map{|p| File.expand_path(p, HAARCASCADES_BASE)},

    :parts => %w(haarcascade_mcs_nose.xml haarcascade_mcs_lefteye.xml
    haarcascade_mcs_righteye.xml).map{|p| File.expand_path(p, HAARCASCADES_BASE)},

    :padding => [0.6] # top, right (=top), bottom (=top), left (=right); same as CSS
  }

  # High chances of false positive
  CONFIG2= {
    :face => %w(haarcascade_frontalface_alt_tree.xml haarcascade_frontalface_alt.xml
    haarcascade_profileface.xml).map{|p| File.expand_path(p, HAARCASCADES_BASE)},

    :padding => [0.8, 0.8, 0.8, 0.8] # top, right (=top), bottom (=top), left (=right); same as CSS
  }

  # Simple, high chances of false positive
  CONFIG3= {
    :face => %w(haarcascade_frontalface_alt_tree.xml).map{|p| File.expand_path(p, HAARCASCADES_BASE)},

    :padding => [0.8, 0.8, 0.8, 0.8] # top, right (=top), bottom (=top), left (=right); same as CSS
  }

Use any of the above, adapt, or create your own configuration.

For padding - just like CSS - 1, 2, 3, or 4 values can be provided.

Also see [paperclip-facecrop] (https://github.com/dagi3d/paperclip-facecrop) for few more details.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

face_roi's People

Contributors

kum-deepak avatar

Watchers

James Cloos avatar kingston avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.