def process_image(orig_im):
# Load and scale down image.
scale, im = downscale_image(orig_im)
# Reduce noise.
blur = reduce_noise_raw(im.copy())
# Edged.
edges = auto_canny(blur.copy())
# Reduce noise and remove thin borders.
debordered = reduce_noise_edges(edges.copy())
# Dilate until there are a few components.
dilation, rects, num_tries = find_components(debordered, 16)
# Find the final crop.
final_rect = find_final_crop(dilation, rects)
# Crop the image and smooth.
cropped = crop_image(orig_im, final_rect, scale)
kernel = np.ones((5, 5), np.float32) / 25
smooth2d = cv2.filter2D(cropped, -1, kernel=kernel)
return (smooth2d, num_tries)
评论列表
文章目录