fix: drop glare holes before the margin and never auto-pick specks

Filtering holes after the margin let -2 mm grow 1 mm specks past the
3 mm cutoff, and could drop real holes shrunk by a positive margin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
immortaly007andClaude Opus 5.5 committed 2026-10-15 15:07:16 +02:00
1 parent abef0f982b
commit 41baa25a01
7 files changed
+59 -25

No files matched your search

+20 -1
View File
@@ -11,7 +11,7 @@ beforeAll(async () => {
});
const params = (overrides: Partial<DetectParams> = {}): DetectParams => ({
threshold: 128, invert: false, seed: null, marginPx: 0, ...overrides,
threshold: 128, invert: false, seed: null, marginPx: 0, minHolePx: 0, ...overrides,
});
/** Light plate x 40..159, y 30..129 with hole r=15 at (100,80), plus a small light blob, on dark ground. */
@@ -84,4 +84,23 @@ describe('detect', () => {
});
expect(detect(cv, speckled, params())!.holes).toHaveLength(0);
});
it('fills specks smaller than minHolePx before the margin can grow them', () => {
const glare = grayImage(200, 160, (x, y) => {
const plate = inRect(x, y, 40, 30, 160, 130) && !inCircle(x, y, 100, 80, 15) && !inCircle(x, y, 60, 50, 3);
return plate ? 220 : 30;
});
expect(detect(cv, glare, params({ marginPx: -6 }))!.holes).toHaveLength(2);
expect(detect(cv, glare, params({ marginPx: -6, minHolePx: 10 }))!.holes).toHaveLength(1);
});
it('keeps a long thin hole that is under minHolePx in only one direction', () => {
const slotted = grayImage(200, 160, (x, y) => (inRect(x, y, 40, 30, 160, 130) && !inRect(x, y, 60, 60, 120, 66) ? 220 : 30));
expect(detect(cv, slotted, params({ minHolePx: 10 }))!.holes).toHaveLength(1);
});
it('does not auto-pick a speck when the real piece touches the border', () => {
const framed = grayImage(400, 300, (x, y) => (inRect(x, y, 0, 60, 240, 260) || inRect(x, y, 330, 100, 340, 110) ? 220 : 30));
expect(detect(cv, framed, params())).toBeNull();
});
});