1

I currently extract text from image using:

import png:- | convert png:- -units PixelsPerInch -resample 300 -sharpen 12x6.0 png:- | tesseract -l eng stdin stdout | xsel -ib

However, import png:- command to take screenshot is not working well for me. It somehow do not quite suit Linux Mint.

enter image description here

Is there any other command which I can use to directly send screenshot to STDOUT for further processing.

2
  • I'll assume this is Xorg, not wayland, right? Feb 9, 2022 at 15:42
  • yes this is xorg. Feb 9, 2022 at 15:48

3 Answers 3

1

I remember having similar issues with scrot. In that case I added a sleep and it was fine! Worked fine for me, but I'm not on Linux Mint.

{ import png:-; sleep 0.1 ;} | convert png:- -units PixelsPerInch -resample 300 -sharpen 12x6.0 png:- | tesseract -l eng stdin stdout | xsel -ib

Also, you could try out scrot with something like:

scrot -s aoeu.png -e 'tesseract -l eng $f stdout | xsel -ib; rm -f $f'

A version incorporating input in comments and the answer from J. Cravens

scrot -s -f -q 100 --silent - |
    convert - -units PixelsPerInch -resample 300 -sharpen 12x6.0 - |
    tesseract -l eng stdin stdout |
    xsel -ib
6
  • Thank you very much. The command that is working for me is: scrot -s -f -e 'convert $f -units PixelsPerInch -resample 300 -sharpen 12x6.0 png:- | tesseract -l eng stdin stdout | xsel -ib; rm -f $f'. -f freeze the screen and the problem goes away. However, if there any way to send file as png directly to stdout so that i do not have to write to the disk. Feb 10, 2022 at 6:21
  • The solution I am currently using is : maim -s | convert - -units PixelsPerInch -resample 300 -sharpen 12x6.0 - | tesseract -l eng stdin stdout | xsel -ib Feb 10, 2022 at 8:09
  • Did you test scrot - in your pc. The - does not work in my machine. It does not send anything to stdout. Feb 10, 2022 at 19:52
  • Yes! Tested with scrot version 1.7. Feb 10, 2022 at 20:25
  • Mine is 1.2 probably that is why it is not working. Feb 10, 2022 at 20:45
1

You can use scrot with - for standard output, but it will default save a png file. Just add:

scrot -q 100 --silent - |

Should be exactly what it was looking for.

UPDATE: To do this with versions below 1.7, as it does not accept - as stdout, will be a bit more tricky. Here's a shell script:

#!/bin/bash

#Create a temp working directory
temp_dir=$(mktemp -d)
temp_file="$temp_dir/screenshot_$(date +"%Y%m%d%H%M%S").png"

#Take a screenshot to the temp file
scrot -s -f -q 100 --silent "$temp_file"

#Process the screenshot from temp
convert "$temp_file" -units PixelsPerInch -resample 300 -sharpen 12x6.0 - |
tesseract -l eng stdin stdout |
xsel -ib

#Working directory clean up
rm -r "$temp_dir"

Save it to screenshot.sh
Then, make it executable with chmod +x screenshot.sh
Finally, run ./screenshot.sh

6
  • scrot -s -f works for me, but not understanding how to send this image to stdout. Feb 10, 2022 at 6:00
  • That is what the - before the | indicates is to stdout, easy as that. The -q is quality and default was 75 and given you are extracting text, I figured best quality possible. The --silent part is just in case, avoid problems before they happen.
    – J. Cravens
    Feb 10, 2022 at 11:19
  • I should probably incorporate your answer in mine! Feb 10, 2022 at 12:08
  • Great work! Nice and tidy. 👍
    – J. Cravens
    Feb 10, 2022 at 18:01
  • using - for standard output works in current (v1.7) but doesn't work with earlier versions (v1.4) packaged with Ubuntu 20.04 LTS or earlier.
    – Teque5
    Aug 2, 2022 at 22:25
0

KDE's spectacle screenshot tool lets you output to stdout, but only using /dev/stdout instead of -:

spectacle --background --fullscreen --output /dev/stdout

or, with short options: spectacle -bfo /dev/stdout

New contributor
kwzuu is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

You must log in to answer this question.

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