Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,7 @@ cython_debug/
*.png
*.gif
output*.txt


#Ignore vscode AI rules
.github/instructions/codacy.instructions.md
2 changes: 1 addition & 1 deletion OCR4Linux.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ========================================================================================================================
# Author:
# Mohamed Hussein Al-Adawy
# Version: 1.3.0
# Version: 1.4.0
# Description:
# OCR4Linux.py is a Python script that handles image preprocessing and text extraction using Tesseract OCR.
# The script takes an input image, processes it for optimal OCR accuracy, and extracts text while preserving
Expand Down
14 changes: 11 additions & 3 deletions OCR4Linux.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# ========================================================================================================================
# Author: Mohamed Hussein Al-Adawy
# Version: 1.2.0
# Version: 1.4.0
# Description:
# OCR4Linux is a versatile text extraction tool for Linux systems that:
# 1. Takes screenshots of selected areas using:
Expand Down Expand Up @@ -189,14 +189,18 @@ choose_lang() {

# take shots using grimblast for wayland
takescreenshot_wayland() {
log_message "Taking screenshot using grimblast for Wayland..."
sleep $SLEEP_DURATION
grimblast --notify copysave area "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME in wayland session"
}

# take shots using scrot for x11
takescreenshot_x11() {
log_message "Taking screenshot using scrot for X11..."
sleep $SLEEP_DURATION
scrot -s -Z 0 -o -F "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME in x11 session"
}

# Run the screenshot functions based on the session type.
Expand All @@ -206,7 +210,6 @@ takescreenshot() {
else
takescreenshot_x11
fi
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
}

# Pass the screenshot to OCR tool to extract text from the image.
Expand All @@ -232,13 +235,18 @@ extract_text() {

# Copy the extracted text to clipboard using wl-copy and cliphist.
copy_to_wayland_clipboard() {
log_message "Copying extracted text to Wayland clipboard using wl-copy and cliphist..."
cliphist store <"$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
cliphist list | head -n 1 | cliphist decode | wl-copy
log_message "Extracted text copied to Wayland clipboard successfully."
}

# Copy the extracted text to clipboard using xclip.
copy_to_x11_clipboard() {
xclip -selection clipboard -t text/plain -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
log_message "Copying extracted text to X11 clipboard using xclip..."
xclip -selection clipboard -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
xclip -selection primary -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
log_message "Extracted text copied to X11 clipboard successfully."
}

# Run the copy to clipboard functions based on the session type.
Expand Down
21 changes: 19 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ========================================================================================================================
# Author:
# Mohamed Hussein Al-Adawy
# Version: 1.3.0
# Version: 1.4.0
# Description:
# This setup script installs and configures OCR4Linux and its dependencies.
# It handles the installation of:
Expand Down Expand Up @@ -53,39 +53,56 @@ x11_session_apps=(

# Check if yay is installed.
check_yay() {
echo "Checking for yay AUR helper..."
if ! command -v yay &>/dev/null; then
read -r -p "yay is not installed. Do you want to install yay? (y/n): " choice
if [ "$choice" = "y" ]; then
sudo pacman -S --needed --noconfirm git base-devel
git clone https://aur.archlinux.org/yay.git
cd yay || exit
makepkg -si --noconfirm
echo "yay has been installed successfully."
else
echo "Please install yay first!"
return 1
fi
else
echo "yay is already installed."
fi
}

# Install the required packages.
install_requirements() {
echo "Installing system requirements..."
yay -S --noconfirm --needed "${sys_requirements[@]}"

if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
echo "Installing Wayland session applications..."
yay -S --noconfirm --needed "${wayland_session_apps[@]}"
else
echo "Installing X11 session applications..."
yay -S --noconfirm --needed "${x11_session_apps[@]}"
fi

echo "All requirements have been installed successfully."
}

# Main function.
main() {
echo "========================================================================================================"
echo "Starting OCR4Linux setup..."
echo "========================================================================================================"
check_yay
echo "========================================================================================================"
install_requirements

echo "========================================================================================================"
# Copy the script to the user's home directory.
echo "Setting up OCR4Linux configuration..."
mkdir -p "$HOME/.config/OCR4Linux"
cp -r ./* "$HOME/.config/OCR4Linux"
echo "OCR4Linux has been set up successfully in $HOME/.config/OCR4Linux"
echo "Setup completed. You can now use OCR4Linux."
echo "========================================================================================================"
}

main
Loading