Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from clarifai import rest
from import ClarifaiApp
from import Image as ClImage
from PIL import Image as PilImage
CLARIFAI_APP_ID = "some_long_string"
CLARIFAI_APP_SECRET = "some_long_string"
##Grab the image
the_image = 'path/to/image.jpg'
smiley = '/path/to/overlay.jpg'
##face recognition model
model = app.models.get('a403429f2ddf4b49b307e318f00e528b')
image = ClImage(filename=the_image)
data = model.predict([image])
##find the bounding box
box = data['outputs'][0]['data']['regions'][1]['region_info']['bounding_box']
back =
back_w, back_h = back.size
fore =
smiley_width = (box['right_col'] - box['left_col']) * back_w
smiley_height = (box['bottom_row'] - box['top_row']) * back_h
maxsize = (smiley_width, smiley_height)
fore.thumbnail(maxsize, PilImage.ANTIALIAS)'temp.png')
#temp ='temp.png')
back.paste(fore, (round(box['left_col'] * back_w), round(box['top_row'] * back_h)), fore)'out.png')
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.