def aspect_ratio_score(contour):
rect = cv2.minAreaRect(contour)
width = rect[1][0]
height = rect[1][1]
ratio_score = 0.0
# check to make sure the size is defined to prevent possible division by 0 error
if width != 0 and height != 0:
# the target is 1ft8in wide by 1ft2in high, so ratio of width/height is 20/14
ratio_score = 100 - abs((width / height) - (20 / 14))
return ratio_score
评论列表
文章目录