microsoft / microsoft/markitdown
[BUG]: fix, 解决markitdown-ocr因bbox的top值导致解析pdf文件图片识别的问题
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 186k
- Forks
- 13.7k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 49
Description
_pdf_converter_with_ocr.py
问题:当PDF 的内容是“一整页大图”(扫描/截图型),pdfplumber.page.extract_text() 取不到文字时,只能靠把图片提取出来再走 OCR。
但原来的图片提取逻辑在这个 PDF 上失败了: page.images 里虽然有图,但它的 bbox 的 top 是一个极小的负数( -1.999e-05 )。原代码直接拿这个 bbox 去 page.within_bbox(bbox) ,会触发 ValueError: Bounding box ... is not fully within parent page bounding box ... ,异常被吞掉后就表现为“取不到图片”,因此 OCR 没有输入,结果只剩 ## Page 1 。
修复逻辑:在 _pdf_converter_with_ocr.py 的 _extract_images_from_page() 里,给 bbox 做了 clamp 到 page.bbox (把 top/left 至少拉回到 0,把 bottom/right 限制在页面范围内),避免 within_bbox 因“越界一点点”直接报错,从而现在能稳定提取到图片流并送去 OCR。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in _pdf_converter_with_ocr.py, specifically _extract_images_from_page(), and use the attached PDF example to reproduce the failure. Check the page image bbox handling and verify that extraction reaches OCR instead of producing only “## Page 1”; done means the slightly out-of-bounds bbox no longer raises an exception and the page image is recognized.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100