def getPaddedROI(img, center_x, center_y, width, height):
    paddingColor = [0, 0, 0]
    top_left_x = ((center_x - int((width / 2))) - 1)
    top_left_y = ((center_y - int((height / 2))) - 1)
    bottom_right_x = (center_x + int((width / 2)))
    bottom_right_y = (center_y + int((height / 2)))
    img_height = np.size(img, 0)
    img_width = np.size(img, 1)
    if ((top_left_x < 0) or (top_left_y < 0) or (bottom_right_x > img_width) or (bottom_right_y > img_height)):
        border_left = 0
        border_right = 0
        border_top = 0
        border_bottom = 0
        if (top_left_x < 0):
            width = (width + top_left_x)
            border_left = ((- 1) * top_left_x)
            top_left_x = 0
        if (top_left_y < 0):
            height = (height + top_left_y)
            border_top = ((- 1) * top_left_y)
            top_left_y = 0
        if (bottom_right_x > img_width):
            width = (width - (bottom_right_x - img_width))
            border_right = (bottom_right_x - img_width)
        if (bottom_right_y > img_height):
            height = (height - (bottom_right_y - img_height))
            border_bottom = (bottom_right_y - img_height)
        img_roi = img[top_left_y:bottom_right_y, top_left_x:bottom_right_x]
        img_roi = cv2.copyMakeBorder(img_roi, border_top, border_bottom, border_left, border_right, cv2.BORDER_CONSTANT, value=paddingColor)
    else:
        img_roi = img[top_left_y:bottom_right_y, top_left_x:bottom_right_x]
    return img_roi
def getPaddedROI(img, center_x, center_y, width, height):
    paddingColor = [0, 0, 0]
    top_left_x = ((center_x - int((width / 2))) - 1)
    top_left_y = ((center_y - int((height / 2))) - 1)
    bottom_right_x = (center_x + int((width / 2)))
    bottom_right_y = (center_y + int((height / 2)))
    img_height = np.size(img, 0)
    img_width = np.size(img, 1)
    if ((top_left_x < 0) or (top_left_y < 0) or (bottom_right_x > img_width) or (bottom_right_y > img_height)):
        border_left = 0
        border_right = 0
        border_top = 0
        border_bottom = 0
        if (top_left_x < 0):
            width = (width + top_left_x)
            border_left = ((- 1) * top_left_x)
            top_left_x = 0
        if (top_left_y < 0):
            height = (height + top_left_y)
            border_top = ((- 1) * top_left_y)
            top_left_y = 0
        if (bottom_right_x > img_width):
            width = (width - (bottom_right_x - img_width))
            border_right = (bottom_right_x - img_width)
        if (bottom_right_y > img_height):
            height = (height - (bottom_right_y - img_height))
            border_bottom = (bottom_right_y - img_height)
        img_roi = img[top_left_y:bottom_right_y, top_left_x:bottom_right_x]
        img_roi = cv2.copyMakeBorder(img_roi, border_top, border_bottom, border_left, border_right, cv2.BORDER_CONSTANT, value=paddingColor)
    else:
        img_roi = img[top_left_y:bottom_right_y, top_left_x:bottom_right_x]
    return img_roi