In [5]:
from SimpleCV import *
from time import sleep
#import pytesseract
from bs4 import BeautifulSoup
Here we set up the camera
In [6]:
cam = Camera()
Now we also get a single image from the cam, so mug it up!
In [7]:
img = cam.getImage()
In Ipython Notebook, you can sometimes use TAB autocompletion if the variable is in memory.
Let's see what "sh" brings up.
img.sh
Let's try shrinking beforehand
In [8]:
img.scale(0.5).show()
# Okay, let's keep that
img = img.scale(0.5)
Let's try getting some documentation
In [9]:
img.edges?
Okay, cool - built in documentation. Good.
Let's draw some text on it.
In [10]:
# This draws directly onto the image (in place)
img.drawText('RASPBERRY Pi', 10, 10, color=Color.BLUE, )
img.show()
Out[10]:
In [11]:
#Let's try bigger font
img.drawText('RASPBERRY Pi', 10, 10, color=Color.ORANGE, fontsize=50)
img.drawText('SimpleCV', 10, 100, color=Color.ORANGE, fontsize=50)
img.show()
Out[11]:
In [12]:
#from SimpleCV import Image, Color, Display
# Make a function that does a half and half image.
def halfsies(left,right):
result = left
# crop the right image to be just the right side.
crop = right.crop(right.width/2.0,0,right.width/2.0,right.height)
# now paste the crop on the left image.
result = result.blit(crop,(left.width/2,0))
# return the results.
return result
# Load an image from imgur.
#img = Image('http://i.imgur.com/lfAeZ4n.png')
# binarize the image using a threshold of 90
# and invert the results.
output = img.binarize().invert()
# create the side by side image.
result = halfsies(img,output)
result.show()
Out[12]:
In [12]:
Let's look at some people
Who's there?
This function lists what features we can detect (built in).
In [13]:
img.listHaarFeatures()
In [14]:
ppl = Image('group.jpg')
ppl = Image('tng.jpg')
ppl.show()
Out[14]:
In [15]:
#obs = ppl.findHaarFeatures('face.xml')
obs = ppl.findHaarFeatures('upper_body.xml')
for f in obs:
print str(f.coordinates())
f.draw(color=Color.YELLOW, width=4)
ppl.show()
Out[15]:
Look at the image set as a whole
In [16]:
print obs.sortX()
# Highlight the person on the end
feat1 = obs.sortX()[-1]
feat1.draw(color=Color.RED, width=4)
feat2 = obs.sortX()[0]
# reshow the image after drawing in it
ppl.show()
Out[16]:
In [17]:
# Here's a function that may help you swap parts in two images.
def swap( img1, f1, f2):
# Gte a "mask" that is the first feature cropped and ressized
# to the size of the second feature.
f1mask = f1.crop().resize(w=f2.width(), h=f2.height())
# get the similar for the other
f2mask = f2.crop().resize(w=f1.width(), h=f1.height())
# Set up the output images
out1 = img1.blit( f2mask, f1.topLeftCorner(), alpha=0.8)
out2 = out1.blit( f1mask, f2.topLeftCorner(), alpha=0.8)
return out1, out2
In [18]:
# Run the swap and ignore the first return value
img3, img4 = swap( ppl, feat1, feat2)
img4.show()
Out[18]:
In [ ]:
while True:
# Reduce the image size
img = cam.getImage().scale(0.5)
faces = img.findHaarFeatures("face.xml")
for f in faces:
f.draw(width=3)
img.show()
In [ ]:
### NOTE: I think you'll want to move this code to the while loop above so it's executed repeatedly.
# That while loop never exits right now (always True)
face1 = faces.sortX()[]
face2= faces.sortX()[1]
img1 = swap (img, face1, face2)
img1.show()
In [ ]: