Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
move face detection logic into Rekognition class
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Oct 10, 2012
1 parent aec209c commit 89cabe7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
14 changes: 1 addition & 13 deletions lib/mustachio.rb
Expand Up @@ -42,19 +42,7 @@ def setup_rekognition
require File.join(File.dirname(__FILE__), 'mustachio', 'rekognition') require File.join(File.dirname(__FILE__), 'mustachio', 'rekognition')


self.setup_face_detection do |file| self.setup_face_detection do |file|
json = Rekognition.json file, 'face_part' Mustachio::Rekognition.face_detection file
width, height = Rekognition.dims file

json['face_detection'].map do |entry|
mouth_left, mouth_right, nose = entry.values_at('mouth_l', 'mouth_r', 'nose').map do |dims|
{
'x' => ((dims['x'].to_f / width) * 100.0),
'y' => ((dims['y'].to_f / height) * 100.0)
}
end

{ 'mouth_left' => mouth_left, 'mouth_right' => mouth_right, 'nose' => nose }
end
end end
end end


Expand Down
16 changes: 16 additions & 0 deletions lib/mustachio/rekognition.rb
Expand Up @@ -26,6 +26,22 @@ def json file, jobs = 'face'
def dims file def dims file
`identify -format "%wx%h" #{file.path}`.strip.split('x').map(&:to_f) `identify -format "%wx%h" #{file.path}`.strip.split('x').map(&:to_f)
end end

def face_detection file
json = self.json file, 'face_part'
width, height = self.dims file

json['face_detection'].map do |entry|
mouth_left, mouth_right, nose = entry.values_at('mouth_l', 'mouth_r', 'nose').map do |dims|
{
'x' => ((dims['x'].to_f / width) * 100.0),
'y' => ((dims['y'].to_f / height) * 100.0)
}
end

{ 'mouth_left' => mouth_left, 'mouth_right' => mouth_right, 'nose' => nose }
end
end


end end
end end
Expand Down

0 comments on commit 89cabe7

Please sign in to comment.