Guest User

Untitled

a guest
Jul 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. client = Algorithmia.client()
  2. TEMP_COLLECTION = 'data://.session/'
  3. BOUNDING_BOX_ALGO = 'util/BoundingBoxOnImage/0.1.x'
  4.  
  5. def draw_boxes_and_save(image, output_path, box_data):
  6. request = {}
  7. remote_image = TEMP_COLLECTION + image.split('/')[-1]
  8. temp_output = TEMP_COLLECTION + '1' + image.split('/')[-1]
  9. client.file(remote_image).putFile(image)
  10. request['imageUrl'] = remote_image
  11. request['imageSaveUrl'] = temp_output
  12. request['style'] = 'basic'
  13. boxes = []
  14. for box in box_data:
  15. coords = box['coordinates']
  16. coordinates = {'left': coords['x0'], 'right': coords['x1'],
  17. 'top': coords['y0'], 'bottom': coords['y1']}
  18. text_objects = [{'text': box['label'], 'position': 'top'},
  19. {'text': 'score: {}%'.format(box['confidence']), 'position': 'bottom'}]
  20. boxes.append({'coordinates': coordinates, 'textObjects': text_objects})
  21. request['boundingBoxes'] = boxes
  22. temp_image = client.algo(BOUNDING_BOX_ALGO).pipe(request).result['output']
  23. local_image = client.file(temp_image).getFile().name
  24. client.file(output_path).putFile(local_image)
  25. return output_path
Add Comment
Please, Sign In to add comment