Skip to content

Instantly share code, notes, and snippets.

@StayerX
Created June 5, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StayerX/a0879aa6284521f097b4740d7c892683 to your computer and use it in GitHub Desktop.
Save StayerX/a0879aa6284521f097b4740d7c892683 to your computer and use it in GitHub Desktop.
OCR Images to text
#!/usr/bin/env bash
# Description: OCR images to text
# Requires: tesseract-ocr imagemagick xsel
# Usage: ocr-image <image(s)>
__ocr_image() {
local image
for image in "$@"; do
local tmp_img=$(mktemp)
cp "$image" "$tmp_img.png"
mogrify -modulate 100,0 -resize 700% "$tmp_img.png"
tesseract "$tmp_img.png" "$tmp_img" &> /dev/null
cp "$tmp_img.txt" "$image.txt"
done
exit 0
}
__ocr_image "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment