A macOS command-line OCR tool powered by Apple's Vision framework. Extracts text from images with automatic language detection.
brew install maoxiaoke/tap/ocr
ocr photo.pngbrew install maoxiaoke/tap/ocrcurl -fsSL https://raw.githubusercontent.com/maoxiaoke/macos-vision-ocr/main/install.sh | bashgit clone https://github.com/maoxiaoke/macos-vision-ocr.git
cd macos-vision-ocr
swift build -c release --arch arm64 # Apple Silicon
# swift build -c release --arch x86_64 # Intel
cp .build/release/ocr /usr/local/bin/ocr# Extract text from an image (outputs plain text by default)
ocr image.png
# Multiple images
ocr a.png b.png c.png
# Output as JSON with position data
ocr --json image.png# Save result to a directory
ocr image.png --output ./results
# JSON output to file
ocr --json image.png --output ./results# Process all images in a directory
ocr --img-dir ./images --output-dir ./output
# Merge all results into a single text file
ocr --img-dir ./images --output-dir ./output --mergeLanguages are auto-detected on macOS 13+. You can also specify manually:
ocr image.png --rec-langs "zh-Hans, en-US"
# Show all supported languages
ocr --langGenerates an annotated image with red bounding boxes around detected text:
ocr image.png --debugUSAGE: ocr [<input-files> ...] [options]
ARGUMENTS:
<input-files> Image file path(s) to process
OPTIONS:
--json Output as JSON with position data
--img <path> Path to a single image file
--output <path> Output directory for single image mode
--img-dir <path> Directory containing images for batch mode
--output-dir <path> Output directory for batch mode
--merge Merge all text outputs into a single file
--debug Draw bounding boxes on the image
--rec-langs <langs> Recognition languages (auto-detected if not specified)
--lang Show supported recognition languages
-h, --help Show help information
When using --json, the output includes text positions and confidence scores:
{
"texts": "Detected text content...",
"info": {
"filepath": "./images/handwriting.webp",
"filename": "handwriting.webp",
"width": 1600,
"height": 720
},
"observations": [
{
"text": "Detected line of text",
"confidence": 0.95,
"quad": {
"topLeft": { "x": 0.09, "y": 0.28 },
"topRight": { "x": 0.88, "y": 0.28 },
"bottomRight": { "x": 0.88, "y": 0.35 },
"bottomLeft": { "x": 0.09, "y": 0.35 }
}
}
]
}English, French, Italian, German, Spanish, Portuguese (Brazil), Simplified Chinese, Traditional Chinese, Simplified Cantonese, Traditional Cantonese, Korean, Japanese, Russian, Ukrainian, Thai, Vietnamese.
const { execSync } = require("child_process");
// Plain text
const text = execSync('ocr image.png').toString();
// JSON with positions
const json = JSON.parse(execSync('ocr --json image.png').toString());
console.log(json.texts);
console.log(json.observations);- macOS 10.15+ (macOS 13+ recommended for auto language detection)
- arm64 (Apple Silicon) or x86_64 (Intel)
# Homebrew
brew uninstall ocr
# curl install
rm /usr/local/bin/ocrMIT License - see LICENSE for details.
