def cropped_image(image, contours, min_aspect_ratio=0.5, show=False):
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
original_height, original_width, original_channels = image.shape
if not (original_height > original_width) is (height > width):
warped = cv2.transpose(warped)
warped = cv2.flip(warped, 0)
if show: #this is for debugging puposes
cv2.imshow("Payload", warped)
cv2.waitKey(0)
cv2.destroyAllWindows()
return warped
# def test(canny, opt1, opt2, opt3, polydb, image_file):
# image = cv2.imread(image_file)
# if canny:
# # done_image = sharpen_image(image)
# done_image = filter_image(image, canny1=opt1, canny2=opt2, show=True)
# else:
# contrasted_image = contrast_image(image, thresh1=opt1, thresh2=opt2, show=True)
# done_image = merge_image_contours(contrasted_image, distance=opt3, show=True)
# contours = get_contours(done_image, polydb=polydb)
# overlay(image, contours, show=True)
# cropped_image(image, contours, min_aspect_ratio=0.5, show=True)
# test(True, 5, 5, 0, 0.03, 'images\\1.jpg')
# test(True, 5, 5, 0, 0.03, 'images\\2.jpg')
# test(True, 8, 8, 0, 0.1, 'images\\5.jpg')
# test(True, 5, 5, 0, 0.03, 'images\\6.jpg')
# test(True, 5, 5, 0, 0.03, 'images\\7.jpg')
# test(False, 180, 200, 50, 0.03, 'images\\8.jpg')
# test(True, 5, 5, 0, 0.03, 'images\\9.jpg')
# test(True, 5, 5, 0, 0.03, 'images\\D.jpg')
评论列表
文章目录