title: How to use normalized coordinates in a rectangle for OpenCV
body: <p>I'm using the Microsoft Custom Vision service for object detection with the Python SDK. I'm able to make predictions and I'm trying to use the bounding box information that comes back from the prediction to overlay a rectangle on the image using OpenCV.</p>
  
  <p>However, I'm not sure how to exactly calculate from the normalized coordinates that come back from the Custom Vision service to the point vertexes that the OpenCV <code>rectangle</code> function takes in.</p>
  
  <p>Here's an example of what comes back from the service as bounding box:</p>
  
  <pre><code>{'left': 0.146396145,
   'top': 0.0305180848,
   'width': 0.373975337,
   'height': 0.570280433}
  </code></pre>
  
  <p>Currently, I'm doing these calculations below. The <code>x</code> and <code>y</code> values look like they're being calculated correctly, but I'm not sure how to calculate the second vertex. The image shape was resized to <code>(400, 400)</code>.</p>
  
  <pre><code>for pred in predictions:
      x = int(pred.bounding_box.left * img.shape[0])
      y = int(pred.bounding_box.top * img.shape[1])
  
      width = int(pred.bounding_box.width * img.shape[0])
      height = int(pred.bounding_box.height * img.shape[1])
  
      img = cv2.rectangle(img, (x,y), (width,height), (0,0,255), 2)
  </code></pre>
  
  <p>And here is the resulting image from the above code:
  <a href="https://i.stack.imgur.com/aXrOf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aXrOf.png" alt="enter image description here"></a></p>
  
  <p>The first box looks like it's not going far enough, whereas the second box looks like it produced a rectangle going the opposite way of where it should.</p>
  
  <p>Does anyone know how to calculate these correctly from normalized coordinates?</p>