def _overlap_ratio(box1, box2):
  """Computes overlap ratio of two bounding boxes.

  Args:
    box1: (x, y, width, height).
    box2: (x, y, width, height).

  Returns:
    float, represents overlap ratio between given boxes.
  """

  def _area(box):
    _, _, width, height = box
    area = width * height
    assert area >= 0
    return area

  def _intersection_area(box1, box2):
    x1, y1, width1, height1 = box1
    x2, y2, width2, height2 = box2
    x = max(x1, x2)
    y = max(y1, y2)
    width = max(min(x1 + width1, x2 + width2) - x, 0)
    height = max(min(y1 + height1, y2 + height2) - y, 0)
    area = width * height
    assert area >= 0
    return area

  intersection_area = _intersection_area(box1, box2)
  union_area = _area(box1) + _area(box2) - intersection_area
  assert union_area >= 0
  if union_area > 0:
    return float(intersection_area) / float(union_area)
  return 1.0