Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import picamera, json, requests, os, random
from time import sleep
from PIL import Image, ImageDraw
#capture an image
camera = picamera.PiCamera()
print('caputred image')
#make a prediction on the image
url = ''
data = {'file': open('image1.jpg', 'rb'), \
'modelId': ('', 'YOUR_MODEL_ID')}
response =, auth=requests.auth.HTTPBasicAuth('YOUR_API_KEY', ''), files=data)
#draw boxes on the image
response = json.loads(response.text)
im ="image1.jpg")
draw = ImageDraw.Draw(im, mode="RGBA")
prediction = response["result"][0]["prediction"]
for i in prediction:
draw.rectangle((i["xmin"],i["ymin"], i["xmax"],i["ymax"]), fill=(random.randint(1, 255),random.randint(1, 255),random.randint(1, 255),127))"image2.jpg")
os.system("xdg-open image2.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment