weekly
weekly copied to clipboard
【开源自荐】Ollama-OCR - 使用 Ollama 支持的视觉模型(llama 3.2-vision/minicpm-v 等)实现图片 OCR,支持中文识别和输出 Markdown 文档。
Ollama-OCR 项目地址
https://github.com/bytefer/ollama-ocr
Ollama-OCR 的特点
- 支持使用 Llama 3.2-Vision/ minicpm-v 等 Ollama 支持的视觉模型,进行 OCR 识别
- 保留原始文本格式和结构
- 支持多种图像格式:JPG、JPEG、PNG
- 可自定义的识别提示词和模型
- 支持输出 Markdown 格式文档
使用示例
Ollama-OCR 默认使用 llama3.2-vision 模型,可以通过 model 属性配置其它模型,比如 minicpm-v。
ollama run llama3.2-vision # 下载模型
npm install ollama-ocr
# or using pnpm
pnpm add ollama-ocr
手写图片识别
import { ollamaOCR, DEFAULT_OCR_SYSTEM_PROMPT } from "ollama-ocr";
async function runOCR() {
const text = await ollamaOCR({
filePath: "./handwriting.jpg",
systemPrompt: DEFAULT_OCR_SYSTEM_PROMPT,
});
console.log(text);
}
输入图片:
识别结果: The Llama 3.2-Vision collection of multimodal large language models (LLMs) is a collection of instruction-tuned image reasoning generative models in 118 and 908 sizes (text + images in / text out). The Llama 3.2-Vision instruction-tuned models are optimized for visual recognition, image reasoning, captioning, and answering general questions about an image. The models outperform many of the available open source and closed multimodal models on common industry benchmarks.
输出 Markdown 格式
import { ollamaOCR, DEFAULT_MARKDOWN_SYSTEM_PROMPT } from "ollama-ocr";
async function runOCR() {
const text = await ollamaOCR({
filePath: "./trader-joes-receipt.jpg",
systemPrompt: DEFAULT_MARKDOWN_SYSTEM_PROMPT,
});
console.log(text);
}
输入图片:
识别结果:
使用 minicpm-v 模型
async function runOCR() {
const text = await ollamaOCR({
model: "minicpm-v",
filePath: "./trader-joes-receipt.jpg",
systemPrompt: DEFAULT_MARKDOWN_SYSTEM_PROMPT,
});
console.log(text);
}
在项目中,可以根据实际的应用场景,调整对应的提示词。