1
0
mirror of https://github.com/ciromattia/kcc synced 2026-02-21 11:39:08 +00:00

fix cropping divide by zero (#1220)

This commit is contained in:
Alex Xu
2026-01-20 20:47:56 -08:00
committed by GitHub
parent 4baca03214
commit f5fd2bb7fe

View File

@@ -160,6 +160,8 @@ def ignore_pixels_near_edge(bw_img):
for box in edge_bbox: for box in edge_bbox:
edge = bw_img.crop(box) edge = bw_img.crop(box)
h = edge.histogram() h = edge.histogram()
if not edge.height or not edge.width:
continue
imperfections = h[255] / (edge.height * edge.width) imperfections = h[255] / (edge.height * edge.width)
if imperfections > 0 and imperfections < .02: if imperfections > 0 and imperfections < .02:
bw_img.paste(im=0, box=box) bw_img.paste(im=0, box=box)