Permalink
Browse files

move face detection logic into Rekognition class

  • Loading branch information...
1 parent aec209c commit 89cabe7cc1e4a01977d88e2c825bc02fc0c1407d @afeld committed Oct 10, 2012
Showing with 17 additions and 13 deletions.
  1. +1 −13 lib/mustachio.rb
  2. +16 −0 lib/mustachio/rekognition.rb
View
@@ -42,19 +42,7 @@ def setup_rekognition
require File.join(File.dirname(__FILE__), 'mustachio', 'rekognition')
self.setup_face_detection do |file|
- json = Rekognition.json file, 'face_part'
- 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
+ Mustachio::Rekognition.face_detection file
end
end
@@ -26,6 +26,22 @@ def json file, jobs = 'face'
def dims file
`identify -format "%wx%h" #{file.path}`.strip.split('x').map(&:to_f)
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

0 comments on commit 89cabe7

Please sign in to comment.