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? Commented Feb 9, 2022 at 15:42
  • yes this is xorg. Commented 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. Commented 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 Commented 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. Commented Feb 10, 2022 at 19:52
  • Yes! Tested with scrot version 1.7. Commented Feb 10, 2022 at 20:25
  • Mine is 1.2 probably that is why it is not working. Commented 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_file="$HOME/screenshot_$(date +"%Y_%m_%d-%H_%M_%S").png"

# Take a screenshot to the temp file
scrot -zfq 100 --silent "$temp_file"

# Copy the image file to the clipboard using xclip
xclip -selection clipboard -t image/png -i "$temp_file"

echo -e "\nScreenshot saved to:\n"$temp_file"\n"

exit 0

With xclip, it's ready to paste/output. Piping to xsel etc. should work the same.

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

Tip: Use an alias to run scripts in a single command.
How To Create BASH Aliases

alias sshot='bash -c "/path/to/script/screenshot.sh"'

Now you can take a screenshot by simply typing: sshot

7
  • scrot -s -f works for me, but not understanding how to send this image to stdout. Commented 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.
    – JayCravens
    Commented Feb 10, 2022 at 11:19
  • I should probably incorporate your answer in mine! Commented Feb 10, 2022 at 12:08
  • Great work! Nice and tidy. 👍
    – JayCravens
    Commented 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
    Commented 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

You must log in to answer this question.

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