Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from PIL import Image, ImageDraw
import photos
from objc_util import *
CIImage, CIDetector = map(ObjCClass, ['CIImage', 'CIDetector'])
#imagebuffer = photos.capture_image()
imagebuffer = photos.pick_image()'.temp.jpg')
data = NSData.dataWithContentsOfFile_('.temp.jpg')
ci_img = CIImage.imageWithData_(data)
opt = {'CIDetectorAccuracy': 'CIDetectorAccuracyHigh'}
d = CIDetector.detectorOfType_context_options_('CIDetectorTypeFace', None, opt)
faces = d.featuresInImage_(ci_img)
#print face
if faces.count() > 0:
drawbuffer = ImageDraw.Draw(imagebuffer)
for face in faces:
b = face.bounds()
drawbuffer.rectangle((b.origin.x,imagebuffer.size[1]-(b.origin.y+h), b.origin.x+w,imagebuffer.size[1]-b.origin.y), outline='white')
del drawbuffer
print 'No face detected.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.