this post was submitted on 08 Feb 2024
89 points (97.8% liked)

Linux

45534 readers
1361 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

With modern CPU's supposedly shipping with 'AI cores': How long do you think it will take for a proper opensource, privacy respecting productivity tools(Something like whatever M$ copilot is supposed to be?) to be available?

Personally, i would love to see something like 'Passive' OCR integrated with the display server: the ability to pause any video and just select whatever text(even handwritten) there is naturally like it was a text document without any additional hassle will be really useful
Also useful in circumventing any blocks certain websites put on articles to prevent text from being copied

Or an AI grammar checker running natively for LibreOffice.

What are some AI tools you think should be developed for desktop Linux?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 4 months ago (1 children)

Share the script! Share the script! Share the script! (Nobody will judge you if it is written strangely or is hard to adapt, reading other people’s code is always fun (bash scripts are code fight me))

[–] thevoidzero 1 points 4 months ago

Hi there, I did say it's easily doable, but I didn't have a script because I run things based on the image before OCR manually (like the negating the dark mode I tried in this script; when doing manually it's just one command as I know whether it's dark mode of not myself; similar for the threshold as well).

But here's a one I made for you:

#!/usr/bin/env bash

# imagemagic has a cute little command for importing screen into a file
import -colorspace gray /tmp/screenshot.png
mogrify /tmp/screenshot.png -color-threshold "100-200"
# extra magic to invert if the average pixel is dark
details=`convert /tmp/screenshot.png -resize 1x1 txt:-`
total=`echo $details | awk -F, '{print $4}'`
value=`echo $details | awk '{print $7}'`
darkness=$(( ${value#_(%_)} * 100 / $total ))
if (( $darkness < 50 )); then
   mogrify -negate /tmp/screenshot.png
fi

# now run the OCR
text=`tesseract /tmp/screenshot.png -`
echo $text | xclip -selection c
notify-send OCR-Screen "$text"

So the middle part is to accommodate images in dark mode. It negates it based on the threshold that you can change. Without that, you can just have import for screen capture, tesseract for running OCR. and optionally pipe it to xclip for clipboard or notify-send for notification.

In my use case, I have keybind to take a screenshot like this: import png:- | xclip -selection c -t image/png which gives me the cursor to select part of the screen and copies that to clipboard. I can save that as an image (through another bash script), or paste it directly to messenger applications. And when I need to do OCR, I just run tesseract in the terminal and copy the text from there.