#!/usr/bin/python import time, webbrowser from operator import add from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv from SimpleCV.Display import Display cam = Camera(0) time.sleep(.1) # uhg display = Display((800,600)) counter = 0 # load the cascades face_cascade = cv.Load("./../Features/HaarCascades/face.xml") nose_cascade = cv.Load("./../Features/HaarCascades/nose.xml") stache = Image("./stache.png") # load the stache mask = stache.createAlphaMask() # load the stache mask count = 0 while( display.isNotDone() ): #count = count + 1 img = cam.getImage() img = img.scale(.5) #use a smaller image faces = img.findHaarFeatures(face_cascade) #find faces if( faces is not None ): # if we have a face faces = faces.sortArea() #get the biggest one face = faces[-1] myFace = face.crop() # get the face image noses = myFace.findHaarFeatures(nose_cascade) #find the nose if( noses is not None ):# if we have a nose noses = noses.sortArea() nose = noses[0] # get the biggest # these get the upper left corner of the face/nose
# -*- coding: utf-8 -*- """ Created on Mon Jun 16 13:56:40 2014 @author: Kelly """ from SimpleCV import Camera, Display, Image cam=Camera(0) disp= Display(cam.getImage().size()) stache=Image("mustache.jpg") mask=stache.createAlphaMask() while disp.isNotDone(): img=cam.getImage() faces=img.findHaarFeatures('face') if (faces is not None): face=faces.sortArea()[-1] myface=face.crop() noses=myface.findHaarFeatures('nose') if (noses is not None ): nose=noses.sortArea()[-1] xmust=face.points[0][0]+nose.x+ (stache.width/2) ymust= face.points[0][1]+nose.y+(2*nose.height()/3) img=img.blit(stache,pos=(xmust,ymust), mask=mask) img.save(disp)
from SimpleCV import Display, Image, Color import time imagelist = [ 'faces/face_test_1.jpg', 'faces/face_test_2.jpg', 'faces/face_test_3.jpg', 'faces/face_test_4.jpg', 'faces/face_test_5.jpg', 'faces/face_test_6.jpg' ] imagecycle = 0 image = Image(imagelist[0]) disp = Display(image.size()) apple = Image('Apple.jpg') mask = apple.createAlphaMask(0) print 'Right click to cycle images. Left to remove apple.' def cycle(): global imagecycle global image x = len(imagelist) if (imagecycle + 1 == x): imagecycle = 0 else: imagecycle = imagecycle + 1 image = Image(imagelist[imagecycle]).scale(600, 480) while disp.isNotDone(): x = None y = None width = None height = None coordinates = (x, y)
from SimpleCV import Color, Camera, Display, Image import time cam = Camera() disp = Display(cam.getImage().size()) # Load the stache and alpha mask stache = Image("mustache.png") mask = stache.createAlphaMask() while disp.isNotDone(): img = cam.getImage() faces = img.findHaarFeatures('face') if (faces is not None): # Get the biggest face face = faces.sortArea()[-1] myface = face.crop() # myface.show() noses = myface.findHaarFeatures('nose') # If we have a nose if (noses is not None): nose = noses.sortArea()[-1] # Calculate the mustache position xmust = face.points[0][0] + nose.x + (stache.width / 2) ymust = face.points[0][1] + nose.y + (2 * nose.height() / 3) # Blit the stache/mask onto the image
#!/usr/bin/python import time, webbrowser from operator import add from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv, HaarCascade from SimpleCV.Display import Display cam = Camera(1) time.sleep(.1) # uhg display = Display((800,600)) counter = 0 # load the cascades face_cascade = HaarCascade("./../Features/HaarCascades/face.xml") nose_cascade = HaarCascade("./../Features/HaarCascades/nose.xml") stache = Image("./stache.png") # load the stache mask = stache.createAlphaMask() # load the stache mask count = 0 while( display.isNotDone() ): #count = count + 1 img = cam.getImage() img = img.scale(.5) #use a smaller image faces = img.findHaarFeatures(face_cascade) #find faces if( faces is not None ): # if we have a face faces = faces.sortArea() #get the biggest one face = faces[-1] myFace = face.crop() # get the face image noses = myFace.findHaarFeatures(nose_cascade) #find the nose if( noses is not None ):# if we have a nose noses = noses.sortArea() nose = noses[0] # get the biggest # these get the upper left corner of the face/nose