For those who use Google Lens on Android as an OCR to capture text from images, screenshots, etc.. here is a bash script that does the same on Ubuntu.
Sometimes we need to copy a telephone number in an APP where there isn't a copy to clipboard feature enabled or maybe to copy texts from an picture.
This can be done with a OCR, this script does that allowing to drag&drop select a region of the screen and copy to clipboard the text parsed from the image.
#!/bin/bash
# Dependencies: tesseract-ocr imagemagick scrot xsel
tesseract_lang=eng
# quick language menu, add more if you need other languages.
SCR_IMG=`mktemp`
trap "rm $SCR_IMG*" EXIT
scrot -s $SCR_IMG.png -q 100
# increase image quality with option -q from default 75 to 100
mogrify -modulate 100,0 -resize 400% $SCR_IMG.png
#should increase detection rate
tesseract $SCR_IMG.png $SCR_IMG &> /dev/null
cat $SCR_IMG.txt | xsel -bi
exit
If you save the script in /usr/bin/lens, the usage will be like this:
- ALT+F2, type 'lens' and hit ENTER
- Select the region you want to capture with the mouse
- Paste the clipboard-copied text with the OCR'ed data
Amazing script. Thanks very much for this solution!