本文整理汇总了Python中imutils.contours.sort_contours方法的典型用法代码示例。如果您正苦于以下问题:Python contours.sort_contours方法的具体用法?Python contours.sort_contours怎么用?Python contours.sort_contours使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imutils.contours
的用法示例。
在下文中一共展示了contours.sort_contours方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_top_bottom
# 需要导入模块: from imutils import contours [as 别名]
# 或者: from imutils.contours import sort_contours [as 别名]
def get_top_bottom(cnts):
sort_res = contours.sort_contours(cnts, method="left-to-right")
cents_pos = sort_res[1]
que_cnts = list(sort_res[0])
choice_row_count = get_choice_row_count()
num = len(cents_pos) - choice_row_count + 1
dt = {}
for i in range(num):
distance = 0
for j in range(i, i + choice_row_count - 1):
distance += cents_pos[j + 1][0] - cents_pos[j][0]
dt[distance] = cents_pos[i:i + choice_row_count]
keys = dt.keys()
key_min = min(keys)
if key_min >= 10:
raise
w = sorted(dt[key_min], key=lambda x: x[1])
top, bottom = w[0][1] - w[0][3] * 0.5, w[-1][1] + w[-1][3] * 0.5
count = 0
for i, c in enumerate(cents_pos):
if c[1] < top or c[1] > bottom:
que_cnts.pop(i - count)
count += 1
return que_cnts
示例2: get_left_right
# 需要导入模块: from imutils import contours [as 别名]
# 或者: from imutils.contours import sort_contours [as 别名]
def get_left_right(cnts):
sort_res = contours.sort_contours(cnts, method="top-to-bottom")
cents_pos = sort_res[1]
que_cnts = list(sort_res[0])
que_cnts = delete_rect(cents_pos, que_cnts)
sort_res = contours.sort_contours(que_cnts, method="top-to-bottom")
cents_pos = sort_res[1]
que_cnts = list(sort_res[0])
num = len(cents_pos) - CHOICE_COL_COUNT + 1
dt = {}
for i in range(num):
distance = 0
for j in range(i, i + CHOICE_COL_COUNT - 1):
distance += cents_pos[j + 1][1] - cents_pos[j][1]
dt[distance] = cents_pos[i:i + CHOICE_COL_COUNT]
keys = dt.keys()
key_min = min(keys)
if key_min >= 10:
raise
w = sorted(dt[key_min], key=lambda x: x[0])
lt, rt = w[0][0] - w[0][2] * 0.5, w[-1][0] + w[-1][2] * 0.5
count = 0
for i, c in enumerate(cents_pos):
if c[0] < lt or c[0] > rt:
que_cnts.pop(i - count)
count += 1
return que_cnts