Skip to content

Commit 90a31ac

Browse files
authored
Merge branch 'dev' into dev
2 parents 6f9635b + 1ff23ed commit 90a31ac

File tree

7 files changed

+116
-15
lines changed

7 files changed

+116
-15
lines changed

.github/workflows/lock.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Close stale issues and PR'
2+
on:
3+
schedule:
4+
- cron: '30 1 * * *'
5+
6+
jobs:
7+
stale:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/stale@v9
11+
with:
12+
github-token: ${{secrets.GITHUB_TOKEN}}
13+
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
14+
stale-issue-label: 'no-issue-activity'
15+
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.'
16+
stale-pr-label: 'no-pr-activity'
17+
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
18+
days-before-issue-stale: 30
19+
days-before-pr-stale: 45
20+
days-before-issue-close: 5
21+
days-before-pr-close: 10
22+
exempt-pr-labels: 'awaiting-approval,work-in-progress'
23+
exempt-issue-labels: 'awaiting-approval,work-in-progress,enhancement,bug,autorelease: pending'

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66

77
## Changes
88

9+
### Changed
10+
11+
- OCR: `imagemagick` screenshot preprocessing tuned for better recognition results
12+
913
### Added
1014

1115
- Turkish documentation.
1216
- No changes have been made to other codes.
17+
- OCR: `tesseract` now supports explicit language settings via `hyde/config.toml`:
18+
```toml
19+
[screenshot.ocr]
20+
tesseract_languages = ["eng"]
21+
```
22+
To use text recognition bind `hyde-shell screenshot sc` to any hotkey.
1323

1424
## v25.9.1 (Unreleased)
1525

Configs/.local/lib/hyde/screenshot.sh

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ save_dir="${2:-$XDG_PICTURES_DIR/Screenshots}"
5151
save_file=$(date +'%y%m%d_%Hh%Mm%Ss_screenshot.png')
5252
annotation_tool=${SCREENSHOT_ANNOTATION_TOOL}
5353
annotation_args=("-o" "${save_dir}/${save_file}" "-f" "${temp_screenshot}")
54+
tesseract_default_language=("eng")
55+
tesseract_languages=("${SCREENSHOT_OCR_TESSERACT_LANGUAGES[@]:-${tesseract_default_language[@]}}")
56+
tesseract_languages+=("osd")
5457

5558
if [[ -z "$annotation_tool" ]]; then
5659
pkg_installed "swappy" && annotation_tool="swappy"
@@ -90,6 +93,54 @@ take_screenshot() {
9093
fi
9194
}
9295

96+
ocr_screenshot() {
97+
local mode=$1
98+
shift
99+
local extra_args=("$@")
100+
101+
# execute grimblast with given args
102+
if "$LIB_DIR/hyde/grimblast" "${extra_args[@]}" copysave "$mode" "$temp_screenshot"; then
103+
if pkg_installed imagemagick; then
104+
magick "${temp_screenshot}" \
105+
-colorspace gray \
106+
-contrast-stretch 0 \
107+
-level 15%,85% \
108+
-resize 400% \
109+
-sharpen 0x1 \
110+
-auto-threshold triangle \
111+
-morphology close diamond:1 \
112+
-deskew 40% \
113+
"${temp_screenshot}"
114+
else
115+
notify-send -a "HyDE Alert" "OCR: imagemagick is not installed, recognition accuracy is reduced" -e -i "dialog-warning"
116+
fi
117+
tesseract_package_prefix="tesseract-data-"
118+
tesseract_packages=("${tesseract_languages[@]/#/$tesseract_package_prefix}")
119+
tesseract_packages+=("tesseract")
120+
for pkg in "${tesseract_packages[@]}"; do
121+
if ! pkg_installed "${pkg}"; then
122+
notify-send -a "HyDE Alert" "$(echo -e "OCR: required package is not installed\n ${pkg}")" -e -i "dialog-error"
123+
return 1
124+
fi
125+
done
126+
tesseract_languages_prepared=$(IFS=+; echo "${tesseract_languages[*]}")
127+
tesseract_output=$(tesseract \
128+
--psm 6 \
129+
--oem 3 \
130+
-l ${tesseract_languages_prepared} \
131+
"${temp_screenshot}" \
132+
stdout
133+
2>/dev/null
134+
)
135+
printf "%s" "$tesseract_output" | wl-copy
136+
notify-send -a "HyDE Alert" "$(echo -e "OCR: ${#tesseract_output} symbols recognized\n\nLanguages used ${tesseract_languages[@]/#/'\n '}")" -i "${temp_screenshot}" -e
137+
rm -f "${temp_screenshot}"
138+
else
139+
notify-send -a "HyDE Alert" "OCR: screenshot error" -e -i "dialog-error"
140+
return 1
141+
fi
142+
}
143+
93144
pre_cmd
94145

95146
case $1 in
@@ -106,23 +157,14 @@ m) # print focused monitor
106157
take_screenshot "output"
107158
;;
108159
sc) #? 󱉶 Use 'tesseract' to scan image then add to clipboard
109-
check_package tesseract-data-eng tesseract
110-
if ! GEOM=$(slurp); then
111-
notify-send -a "HyDE Alert" "OCR preview: Invalid geometry" -e -i "dialog-error"
112-
exit 1
113-
fi
114-
grim -g "${GEOM}" "${temp_screenshot}"
115-
pkg_installed imagemagick && magick "${temp_screenshot}" -sigmoidal-contrast 10,50% "${temp_screenshot}"
116-
tesseract "${temp_screenshot}" - | wl-copy
117-
notify-send -a "HyDE Alert" "OCR preview" -i "${temp_screenshot}" -e
118-
rm -f "${temp_screenshot}"
160+
ocr_screenshot "area" "--freeze"
119161
;;
120162
*) # invalid option
121163
USAGE
122164
;;
123165
esac
124166

125-
[ -f "$temp_screenshot" ] && rm "$temp_screenshot"
167+
[ -f "${temp_screenshot}" ] && rm "${temp_screenshot}"
126168

127169
if [ -f "${save_dir}/${save_file}" ]; then
128170
notify-send -a "HyDE Alert" -i "${save_dir}/${save_file}" "saved in ${save_dir}"

Configs/.local/share/hyde/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ annotation_tool = "satty" # Annotation tool for screenshots.
117117
annotation_pre_command = [] # Pre command for annotation tool.
118118
annotation_post_command = [""] # Post command for annotation tool.
119119

120+
# OCR configuration.
121+
[screenshot.ocr]
122+
tesseract_languages = ["eng"] # Place desired languages to use for text recognition. To see installed languages run `tesseract --list-langs`.
123+
120124
# Bookmark configuration.
121125
[rofi.bookmark]
122126

Configs/.local/share/hyde/schema/config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ type = "object"
417417
[properties.screenshot.properties.annotation_post_command.items]
418418
type = "string"
419419

420+
[properties."screenshot.ocr"]
421+
description = "OCR configuration."
422+
type = "object"
423+
424+
[properties."screenshot.ocr".properties.tesseract_languages]
425+
default = [ "eng" ]
426+
description = "Place desired languages to use for text recognition. To see installed languages run `tesseract --list-langs`."
427+
type = "array"
428+
420429
[properties."rofi.bookmark"]
421430
description = "Bookmark configuration."
422431
type = "object"

Configs/.local/share/hyde/schema/config.toml.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,19 @@
457457
}
458458
}
459459
},
460+
"screenshot.ocr": {
461+
"description": "OCR configuration.",
462+
"type": "object",
463+
"properties": {
464+
"tesseract_languages": {
465+
"default": [
466+
"eng"
467+
],
468+
"description": "Place desired languages to use for text recognition. To see installed languages run `tesseract --list-langs`.",
469+
"type": "array"
470+
}
471+
}
472+
},
460473
"rofi.bookmark": {
461474
"description": "Bookmark configuration.",
462475
"type": "object",

Scripts/migrations/v25.9.1.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env sh
22

3-
echo "Replacing rofi-wayland to rofi"
3+
echo "Please be sure to update rofi"
4+
echo "Arch repo now support rofi-wayland inside rofi package"
5+
echo "If you are using arch linux or an arch based distro please remove rofi-wayland and install rofi"
6+
echo "sudo pacman -Syu should also do the trick"
47

5-
sudo pacman -Sy
6-
sudo pacman -Rns --noconfirm rofi-wayland
7-
sudo pacman -S --noconfirm rofi

0 commit comments

Comments
 (0)