本文整理匯總了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