Created
August 8, 2012 19:42
-
-
Save GantMan/3297986 to your computer and use it in GitHub Desktop.
Code for RubyMotion Facial Recognition Blog: http://iconoclastlabs.com/cms/blog/posts/ios-face-detection-in-rubymotion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def draw_feature(context, atPoint:feature_point) | |
size = 6 | |
startx = feature_point.x - (size/2) | |
starty = feature_point.y - (size/2) | |
CGContextAddRect(context, [[startx, starty], [size, size]]) | |
CGContextDrawPath(context, KCGPathFillStroke) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_features features | |
features.each_with_index do |feature, index| | |
p "Found Feature!" | |
if feature.hasLeftEyePosition | |
p "Left Eye Coord: #{feature.leftEyePosition.x}x#{feature.leftEyePosition.y}" | |
end | |
if feature.hasRightEyePosition | |
p "Right Eye Coord: #{feature.rightEyePosition.x}x#{feature.rightEyePosition.y}" | |
end | |
if feature.hasMouthPosition | |
p "Mouth Coord: #{feature.mouthPosition.x}x#{feature.mouthPosition.y}" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGContextTranslateCTM(currentContext, 0, @me.size.height) | |
CGContextScaleCTM(currentContext, 1, -1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def viewDidLoad | |
super | |
view.backgroundColor = UIColor.lightGrayColor | |
@me = UIImage.imageNamed("gantman.jpeg") | |
cme = CIImage.alloc.initWithImage(@me) | |
options = NSDictionary.dictionaryWithObject(CIDetectorAccuracyHigh, forKey:CIDetectorAccuracy) | |
detector = CIDetector.detectorOfType(CIDetectorTypeFace, context:nil, options:options) | |
features = detector.featuresInImage(cme) | |
Dispatch::Queue.concurrent.async do | |
print_features(features) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment