fix: merge nearby spine gaps + handle multi-page crop in frontend
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 31s
CI / test-go-edu-search (push) Successful in 29s
CI / test-python-klausur (push) Failing after 1m53s
CI / test-python-agent-core (push) Successful in 16s
CI / test-nodejs-website (push) Successful in 18s
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 31s
CI / test-go-edu-search (push) Successful in 29s
CI / test-python-klausur (push) Failing after 1m53s
CI / test-python-agent-core (push) Successful in 16s
CI / test-nodejs-website (push) Successful in 18s
Backend: merge gaps within 5% of image width — the spine area may have thin ink strips splitting one physical gap into multiple detected gaps. Only use gaps >= 2% width as split points. Frontend: StepCrop now handles multi_page crop responses without crashing on missing original_size/cropped_size fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -100,12 +100,33 @@ def detect_page_splits(
|
||||
if not gaps:
|
||||
return []
|
||||
|
||||
# Merge nearby gaps (< 5% of width apart) — the spine area may have
|
||||
# thin ink strips between multiple gap segments
|
||||
merge_dist = max(20, int(w * 0.05))
|
||||
merged: list = [gaps[0]]
|
||||
for g in gaps[1:]:
|
||||
prev = merged[-1]
|
||||
prev_end = prev["x"] + prev["width"]
|
||||
if g["x"] - prev_end < merge_dist:
|
||||
# Merge: extend previous gap to cover both
|
||||
new_end = g["x"] + g["width"]
|
||||
prev["width"] = new_end - prev["x"]
|
||||
prev["center"] = prev["x"] + prev["width"] // 2
|
||||
else:
|
||||
merged.append(g)
|
||||
gaps = merged
|
||||
|
||||
# Sort gaps by width (largest = most likely spine)
|
||||
gaps.sort(key=lambda g: g["width"], reverse=True)
|
||||
|
||||
# Use the widest gap(s) as split points
|
||||
# For now: support up to N-1 gaps → N pages
|
||||
split_points = sorted(g["center"] for g in gaps[:3]) # max 4 pages
|
||||
# Use only gaps that are significant (>= 2% of image width)
|
||||
significant_gaps = [g for g in gaps if g["width"] >= w * 0.02]
|
||||
if not significant_gaps:
|
||||
# Fall back to widest gap
|
||||
significant_gaps = [gaps[0]]
|
||||
|
||||
# Use the significant gap(s) as split points
|
||||
split_points = sorted(g["center"] for g in significant_gaps[:3])
|
||||
|
||||
# Build page rectangles
|
||||
pages: list = []
|
||||
|
||||
Reference in New Issue
Block a user