def crop_image(image, contours, min_aspect_ratio=0.5):
ratio = image.shape[0] / float(scale_factor)
warped = four_point_transform(image, contours.reshape(4, 2) * ratio)
# test to see if the box ratio is correct
height, width, channels = warped.shape
if height > width:
aspect_ratio = width / height
else:
aspect_ratio = height / width
if aspect_ratio < min_aspect_ratio:
raise ImageNotReadable()
# test to see if the orientation is correct, if not flip it
if height > width:
warped = cv2.transpose(warped)
warped = cv2.flip(warped, 0)
return warped
评论列表
文章目录