title: Multiple bounding-boxes with cv2.rectangle()
body: <p>I currently have coordinates data for bounding boxes, contained in a nested data structure like so:</p>
  <pre><code> defaultdict(list,
              {'giraffe': [{'conf': 0.9869,
                 'coords': {'center_x': 0.360333,
                  'center_y': 0.532274,
                  'height': 0.596343,
                  'width': 0.144651}},
                {'conf': 0.253321,
                 'coords': {'center_x': 0.016296,
                  'center_y': 0.565007,
                  'height': 0.580526,
                  'width': 0.03498}}],
               'zebra': [{'conf': 0.998863,
                 'coords': {'center_x': 0.545974,
                  'center_y': 0.693267,
                  'height': 0.301859,
                  'width': 0.257102}}]})
  </code></pre>
  <p>I want to iterate through the data structure (<code>img_obj_data</code>) and draw the rectangles for each object per  object_class.</p>
  <p>I want to then save the image (with boxes drawn), so I can open it later.</p>
  <p>My first attempt is below:</p>
  <pre><code>import cv2
  
  img = cv2.imread(img_path)
  img_h, img_w = img.shape[:2]
  
  for obj_class in img_obj_data.keys():
      for sub_dict in img_obj_data[obj_class]:
          x, y, w, h = sub_dict['coords'].values()
          
          # coords cannot be floats
          x = int(x*img_w)
          y = int(y*img_h)
          x_max = int(w*img_w)
          y_max = int(y*img_h)
  
          cv2.rectangle(img, (x, y), (x_max, y_max), color=(0, 255, 0), thickness=2)
  cv2.imwrite('/content/foobar.jpg', img)
  </code></pre>
  <p>I now have run into 2 problems:</p>
  <p><strong>Problem 1)</strong>
  The bounding boxes are not properly aligned with the objects and are cropped out of the image.
  (The coordinates are originally floats, I multiplied them by the image width and height but I have a hunch that this was the incorrect thing to do?)</p>
  <p><strong>Problem 2)</strong></p>
  <p>My code at the moment colours all boxes the same. How can I go about this so that the colours differ per object class?</p>
  <p>Here's the image in question, and the resulting image from my code:
  <a href="https://i.stack.imgur.com/AvSZE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AvSZE.jpg" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/q6L2N.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q6L2N.jpg" alt="enter image description here" /></a></p>