def square(bbox, img_shape):
    """Calculate square bounding box 

    Args:
        bbox (list):[x1, y1, x2, y2]
        img_shape (tuple): (height, width)

    Returns:
        bbox (list)
    """
    x1, y1, x2, y2 = bbox
    w, h = x2 - x1 + 1, y2 - y1 + 1
    if w < h:
        pad = (h - w) // 2
        x1 = max(0, x1 - pad)
        x2 = min(img_shape[1], x2 + pad)
    else:
        pad = (w - h) // 2
        y1 = max(0, y1 - pad)
        y2 = min(img_shape[0], y2 + pad)
    return [x1, y1, x2, y2]
Calculate square bounding box 

    Args:
        bbox (list):[x1, y1, x2, y2]
        img_shape (tuple): (height, width)

    Returns:
        bbox (list)
    
contrib/QualityInspector/qinspector/utils/bbox_utils.py