morphology_utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Shoe-Shape-Classifier 作者: jrzaurin 项目源码 文件源码
def bounding_box(img):
    """
    Returns right, left, lower and upper limits for the limiting box enclosing
    the item (shoe, dress). Note that given the shapes and colors of some items,
    finding the contours and compute the bounding box is not a viable solution.
    """

    is_color = len(img.shape) == 3
    is_grey  = len(img.shape) == 2

    if is_color:
        gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    elif is_grey:
        gray = img.copy()

    slices = gray.mean(axis = 1)[20:gray.shape[0]-30]
    is_white = any(x > 0.9*255 for x in slices)

    if (is_white):
        h1 = min(np.apply_along_axis(get_edges, axis=0, arr=gray , thresh = 0.98)[0,:])
        h2 = max(np.apply_along_axis(get_edges, axis=0, arr=gray , thresh = 0.98)[1,:])
        w1 = min(np.apply_along_axis(get_edges, axis=1, arr=gray , thresh = 0.98)[:,0])
        w2 = max(np.apply_along_axis(get_edges, axis=1, arr=gray , thresh = 0.98)[:,1])
    else :
        h1 = min(np.apply_along_axis(get_edges, axis=0, arr=gray , thresh = 0.9)[0,:])
        h2 = max(np.apply_along_axis(get_edges, axis=0, arr=gray , thresh = 0.9)[1,:])
        w1 = min(np.apply_along_axis(get_edges, axis=1, arr=gray , thresh = 0.9)[:,0])
        w2 = max(np.apply_along_axis(get_edges, axis=1, arr=gray , thresh = 0.9)[:,1])

    return w1, w2, h1, h2
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号