(cnt, image_shape)
return points
Convert rect to xys, i.e., eight points
    The `image_shape` is used to to make sure all points return are valid, i.e., within image area
Convert rect to xys, i.e., eight points
    The `image_shape` is used to to make sure all points return are valid, i.e., within image area
Convert rect to xys i . e . eight points The image_shape is used to to make sure all points return are valid i . e . within image area
def contour_to_xys(cnt, image_shape):
    """Convert rect to xys, i.e., eight points
    The `image_shape` is used to to make sure all points return are valid, i.e., within image area
    """
    rect = cv2.minAreaRect(cnt)
    h, w = image_shape[0:2]
    def get_valid_x(x):
        if x < 0:
            return 0
        if x >= w:
            return w - 1
        return x
    
    def get_valid_y(y):
        if y < 0:
            return 0
        if y >= h:
            return h - 1
        return y
    
    points = cv2.boxPoints(rect)
    points = np.int0(points)
    for i_xy, (x, y) in enumerate(points):
        x = get_valid_x(x)
        y = get_valid_y(y)
        points[i_xy, :] = [x, y]
    points = np.reshape(points, -1)
    return points
def contour_to_xys ( cnt , image_shape ) : rect = cv2 . minAreaRect ( cnt ) h , w = image_shape [ 0 : 2 ] def get_valid_x ( x ) : if x < 0 : return 0 if x >= w : return w - 1 return x def get_valid_y ( y ) : if y < 0 : return 0 if y >= h : return h - 1 return y points = cv2 . boxPoints ( rect ) points = np . int0 ( points ) for i_xy , ( x , y ) in enumerate ( points ) : x = get_valid_x ( x ) y = get_valid_y ( y ) points [ i_xy , : ] = [ x , y ] points = np . reshape ( points , - 1 ) return points