def CalculateScalingFactor(boundingRectangle, desiredSize):
  """ Calculate the scaling factor for the current image to be
      resized to the new dimensions

  :param rect: (x, y, w, h) bounding rectangle of the face
  :param size: (width, height) are the desired dimensions
  :returns: floating point scaling factor
  """
  desiredHeight, desiredWidth = desiredSize
  rectangle_w, rectangle_h = boundingRectangle[2:]
  heightRatio = rectangle_h / desiredHeight
  widthRatio = rectangle_w / desiredWidth
  scalingFactor = 1
  if heightRatio > widthRatio:
    newRectangle_h = 0.95 * desiredHeight
    scalingFactor = newRectangle_h / rectangle_h
  else:
    newRectangle_w = 0.95 * desiredWidth
    scalingFactor = newRectangle_w / rectangle_w
  return scalingFactor