Skip to content

Instantly share code, notes, and snippets.

@runeleaf
Created August 10, 2012 06:18
Show Gist options
  • Save runeleaf/3311681 to your computer and use it in GitHub Desktop.
Save runeleaf/3311681 to your computer and use it in GitHub Desktop.
CameraController
#coding: utf-8
class CameraController < UIViewController
def loadView
self.view = UIImageView.alloc.init
end
def viewDidLoad
BW::Device.camera.any.picture(media_types: [:movie, :image]) do |result|
image = result[:original_image]
image_view = UIImageView.alloc.init
image_view.image = image
#image_view.contentMode = UIViewContentModeScaleAspectFit
image_view.frame = CGRectMake(0, 0, BW::Device.screen.width, BW::Device.screen.height)
#image_view = UIImageView.alloc.initWithImage(image)
#TODO:
ci_image = CIImage.imageWithCGImage(image_view.image.CGImage)
transform = CGAffineTransformMakeScale(image_view.bounds.size.width / image_view.image.size.width, -1 * (image_view.bounds.size.height / image_view.image.size.height))
transform = CGAffineTransformTranslate(transform, 0, -image_view.image.size.height)
@detector ||= CIDetector.detectorOfType CIDetectorTypeFace, context:nil, options: { CIDetectorAccuracy: CIDetectorAccuracyHigh }
@detector.featuresInImage(ci_image, options:{CIDetectorImageOrientation:6}).each do |feature|
puts feature
next unless feature.hasMouthPosition and feature.hasLeftEyePosition and feature.hasRightEyePosition
i = 0
[feature.leftEyePosition,feature.rightEyePosition,feature.mouthPosition].each_with_index do |pt, index|
puts pt.inspect
rect = UIView.alloc.initWithFrame CGRectMake(0, 0, 20, 20)
case i
when 0
# left
rect.backgroundColor = UIColor.redColor.colorWithAlphaComponent(0.2)
when 1
# right
rect.backgroundColor = UIColor.blueColor.colorWithAlphaComponent(0.2)
when 2
# mouth
rect.backgroundColor = UIColor.greenColor.colorWithAlphaComponent(0.2)
end
pt = CGPointApplyAffineTransform(pt, transform)
rect.center = pt
image_view.addSubview(rect)
i += 1
end
end
self.view.addSubview(image_view)
end
end
def imagePickerController(picker, didFinishPickingMediaWithInfo:info)
puts info.objectForKey(UIImagePickerControllerOriginalImage)
end
def imagePickerControllerDidCancel(picker)
picker.presentingViewController.dismissModalViewControllerAnimated(true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment