When I was still using Windows I loved using the capture2text OCR program to grab Japanese kanji from manga and dump them into jisho.org, and was wondering how I could get the same functionality on Ubuntu. Namely:

  1. Take a partial screenshot upon hitting a designated hotkey (click+drag style).
  2. Process the image through an OCR engine.
  3. Output the result into the clipboard.

1 Answer 1


Based off of this script (the 2nd one) I whittled the script down to this:

# Dependencies: tesseract-ocr imagemagick gnome-screenshot xclip


gnome-screenshot -a -f $SCR.png

mogrify -modulate 100,0 -resize 400% $SCR.png 
#should increase detection rate

tesseract $SCR.png $SCR -psm 10 -l jpn
cat $SCR.txt | xclip -selection clipboard
#you can only scan one character at a time


Some goals I had with the modified file:

  1. Removing the need for sudo (to allow for easy hotkey binding)
  2. Replacing scrot (the way gnome-screenshot works looks much nicer IMO)
  3. Simplify the script to something I can more easily understand (removal of temp files)
  4. Limit recognition to one character at a time. (recognition was abysmal without that "-psm 10", and Tesseract kept throwing "empty page" errors as well)

Another two things I did were:

chmod a+x /home/takingitcasual/Documents/Translate/

and setting the temp files permissions to read/write for all. Not sure if it was redundant to do both.

Last thing was giving the bash command

bash /home/takingitcasual/Documents/Translate/screen_ts.sh

a shortcut via this.

If anybody has suggestions on modifying the script or anything else I'd love to hear it. (I have no previous experience with scripting, so I'm sure it can be improved.)

  • I have a similar question related to this question. Can you please check it out askubuntu.com/questions/1038099/… May 19, 2018 at 14:12
  • --psm 10 is useful if the image has a single character.
    – Dominic108
    Apr 28, 2020 at 15:54
  • -l jpn is useful if the text is in Japanese.
    – Dominic108
    Apr 28, 2020 at 15:54
  • -psm is a typo. It must be --psm
    – Dominic108
    Apr 28, 2020 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .