Class: FaceCrop::Detector::FaceCom

Inherits:
Base
  • Object
show all
Defined in:
lib/detectors/face_com.rb

Constant Summary collapse

URL =
"http://api.face.com/faces/detect.json"

Instance Method Summary collapse

Methods inherited from Base

#detect, #initialize

Constructor Details

This class inherits a constructor from FaceCrop::Detector::Base

Instance Method Details

#detect_faces(file) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/detectors/face_com.rb', line 6

def detect_faces(file)
  query = @options.to_query
  url = "#{URL}?#{query}"
  
  response = RestClient.post url, :file => File.new(file)
  response = JSON.parse(response)
  
  photo = response['photos'].first
  photo['tags'].map do |tag|
    # values are returned as percentual values
    x = (photo['width'] * (tag['center']['x'] / 100.0)).to_i
    y = (photo['height'] * (tag['center']['y'] / 100.0)).to_i
    w = (photo['width'] * (tag['width'] / 100)).to_i  
    h = (photo['height'] * (tag['height'] / 100)).to_i
    
    region = FaceCrop::Detector::Region.new(x, y, w, h)
    region.color = "green"
    region
  end
end