Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client = Algorithmia.client()
- TEMP_COLLECTION = 'data://.session/'
- BOUNDING_BOX_ALGO = 'util/BoundingBoxOnImage/0.1.x'
- def draw_boxes_and_save(image, output_path, box_data):
- request = {}
- remote_image = TEMP_COLLECTION + image.split('/')[-1]
- temp_output = TEMP_COLLECTION + '1' + image.split('/')[-1]
- client.file(remote_image).putFile(image)
- request['imageUrl'] = remote_image
- request['imageSaveUrl'] = temp_output
- request['style'] = 'basic'
- boxes = []
- for box in box_data:
- coords = box['coordinates']
- coordinates = {'left': coords['x0'], 'right': coords['x1'],
- 'top': coords['y0'], 'bottom': coords['y1']}
- text_objects = [{'text': box['label'], 'position': 'top'},
- {'text': 'score: {}%'.format(box['confidence']), 'position': 'bottom'}]
- boxes.append({'coordinates': coordinates, 'textObjects': text_objects})
- request['boundingBoxes'] = boxes
- temp_image = client.algo(BOUNDING_BOX_ALGO).pipe(request).result['output']
- local_image = client.file(temp_image).getFile().name
- client.file(output_path).putFile(local_image)
- return output_path
Add Comment
Please, Sign In to add comment