modest improvement to cropping (safer)

This commit is contained in:
2026-09-15 15:13:41 +02:00
parent 9b22a8a137
commit 5b8215e7f5
6 changed files with 56 additions and 9 deletions
+14
View File
@@ -108,6 +108,14 @@ class InkDetectionTests(unittest.TestCase):
.7,(190,190,190),2)
self.assertGreater(detect_bounds(image,dpi=150)['bottom_px'],1100)
def test_sparse_central_pencil_on_dark_grid_survives(self):
image = self.dark_grid()
# Thin, pale handwriting crossing the ruling is split into sparse
# components. Its central position distinguishes it from page holes.
cv2.putText(image,'result',(330,1090),cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
.85,(155,155,155),1)
self.assertGreater(detect_bounds(image,dpi=150)['bottom_px'],1090)
def test_large_unruled_diagram_is_not_paper(self):
image = np.full((1200,850,3),255,np.uint8)
cv2.rectangle(image,(100,100),(750,1100),(20,20,20),3)
@@ -151,6 +159,12 @@ class InkDetectionTests(unittest.TestCase):
r = detect_bounds(image,dpi=150)
self.assertGreater(r['bottom_px'],1060)
def test_faint_page_number_in_outer_band_does_not_block_crop(self):
image = self.dark_grid()
cv2.putText(image,'4/',(3,1160),cv2.FONT_HERSHEY_SIMPLEX,
.55,(130,130,130),1)
self.assertLess(detect_bounds(image,dpi=150)['bottom_px'],850)
def test_faded_neutral_grid(self):
image = self.dark_grid()
image[np.all(image == 65,axis=2)] = 145