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
morphology_utils.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录