跳到正文
DEV Community· Adisorn Khaokom·· 3 小時前AI 評分54

Mac 已有 OCR 引擎,d2md 讓你從終端機使用

Your Mac already has OCR. d2md puts it in your terminal.

AI 導讀

d2md 可在 macOS 終端機調用 Apple Vision OCR,並將辨識結果輸出為 Markdown。作者以本機 d2md 0.1.3 示範英文掃描文件及泰文、日文、中文和韓文合成 PDF,並提供安裝指令 `uv tool install "d2md[ocr]"`;直接 OCR 模式不需要 API key 或額外下載 OCR 模型,但需安裝選用的 OCR 相依套件。

正文

Adisorn Khaokom

Your Mac already has an OCR engine. d2md lets you use it from the terminal and get Markdown back.

On macOS, the direct OCR mode uses Apple Vision. No API key. No extra OCR model to download. You just need the optional OCR dependencies.

Here's the 42-second demo:

Watch the demo on X if the video doesn't load here.

A real scan, with real mistakes

I tried a scanned page from NASA FACTS about the TIROS satellite. It's a public-domain NASA document available through Wikimedia Commons.

This was the command:

d2md nasa.jpg --ocr --lang latin --stdout

Here, latin means the Latin alphabet used in English. For a Thai document, use --lang thai. Leave out --lang to let d2md detect the script automatically.

Part of the output:

THE TIROS SYSTEM
The TIROS satellite is a cylindrical,
300-pound, 18-sided polygon

I've added line breaks to make that excerpt easier to read. Elsewhere on the page, OCR read TV pictures as IV pictures. So yes, check the output.

More than English

The demo also shows Thai, Japanese, Chinese, and Korean. Those are synthetic sample PDFs, and I ran OCR on each one. They aren't scans of real documents.

The Japanese and Chinese results had mistakes elsewhere too. The video shows selected excerpts, not a full accuracy test.

The run used local d2md 0.1.3. The PyPI release may differ. If you want to try the released OCR package, install it with:

uv tool install "d2md[ocr]"

You can use the Markdown in scripts, search, RAG, or give just the text you need to an AI tool.

Code and setup instructions on GitHub. It's open source and MIT-licensed.

來源:DEV Community · dev.to