Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented text recognition (ocr) #272

Merged
merged 29 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
efe7f73
implemented text recognition (ocr)
ston1th Jan 17, 2024
a00dd41
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
ead3463
fixed typo in requirements.txt and make linter happy
ston1th Jan 17, 2024
d36e2d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
c9766bf
keep pillow on windows and more linter fixes
ston1th Jan 17, 2024
8998360
use pathlib to read file
ston1th Jan 17, 2024
f25fc7e
fix str None comparison
ston1th Jan 17, 2024
2f8d298
rewrite some stuff
ston1th Feb 3, 2024
fddd0ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2024
cd2c212
switch back to tesseract
ston1th Feb 3, 2024
80140cb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2024
450b983
Merge branch 'dev' into ocr
Avasam Feb 3, 2024
feeb58e
internal logic changes
ston1th Feb 4, 2024
fb8ed6f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2024
da830c6
import subprocess globally
ston1th Feb 4, 2024
5674088
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2024
b5f6639
make linter happy
ston1th Feb 4, 2024
f1ba410
fixed typo in docstring
ston1th Feb 4, 2024
d1dfff0
input validation and comparison methods
ston1th Feb 10, 2024
f3c0e3e
fix linter
ston1th Feb 10, 2024
3a3015f
Merge branch 'dev' of https://github.com/Toufool/AutoSplit into ocr
ston1th Mar 21, 2024
75cd0e9
improvements to coordinates and matching methods
ston1th Mar 29, 2024
7be9a0e
fix ruff linter
ston1th Mar 29, 2024
043b6b5
Address my own PR comments and fix linting
Avasam Jun 15, 2024
c0b2920
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2024
f2b407a
Merge branch 'dev' into ocr
Avasam Jun 15, 2024
9cd0c2b
STARTUPINFO doesn't exist on Linux
Avasam Jun 16, 2024
2f03a90
More explicit platform check
Avasam Jun 16, 2024
797492f
Fix circular imports, mak OCR as clearly experimental
Avasam Jun 16, 2024
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: 2 additions & 2 deletions src/AutoSplitImage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from enum import IntEnum, auto
from math import sqrt
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, ClassVar

import cv2
import numpy as np
Expand Down Expand Up @@ -41,7 +41,7 @@
image_type: ImageType
byte_array: MatLike | None = None
mask: MatLike | None = None
texts: list[str] = []
texts: ClassVar[list[str]] = []
Avasam marked this conversation as resolved.
Show resolved Hide resolved
# This value is internal, check for mask instead
_has_transparency = False
# These values should be overriden by some Defaults if None. Use getters instead
Expand Down Expand Up @@ -130,7 +130,7 @@

with open(path, encoding="utf-8") as f:
data = toml.load(f)
self.texts = [text.lower().strip() for text in data["texts"]]

Check failure on line 133 in src/AutoSplitImage.py

View workflow job for this annotation

GitHub Actions / Pyright (windows-latest, 3.10)

Cannot assign member "texts" for type "AutoSplitImage*" (reportAttributeAccessIssue)

Check failure on line 133 in src/AutoSplitImage.py

View workflow job for this annotation

GitHub Actions / Pyright (windows-latest, 3.11)

Cannot assign member "texts" for type "AutoSplitImage*" (reportAttributeAccessIssue)

Check failure on line 133 in src/AutoSplitImage.py

View workflow job for this annotation

GitHub Actions / Pyright (windows-latest, 3.12)

Cannot assign member "texts" for type "AutoSplitImage*" (reportAttributeAccessIssue)

Check failure on line 133 in src/AutoSplitImage.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

Cannot assign member "texts" for type "AutoSplitImage*" (reportAttributeAccessIssue)

Check failure on line 133 in src/AutoSplitImage.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

Cannot assign member "texts" for type "AutoSplitImage*" (reportAttributeAccessIssue)
self.__x = abs(data["top_left"])
self.__xx = abs(data["top_right"])
self.__y = abs(data["bottom_left"])
Expand Down
2 changes: 1 addition & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
stdin: int
stdout: int
stderr: int
startupinfo: subprocess.STARTUPINFO | None

Check failure on line 82 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

Type of "STARTUPINFO" is unknown (reportUnknownMemberType)

Check failure on line 82 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

"STARTUPINFO" is not a known member of module "subprocess" (reportAttributeAccessIssue)

Check failure on line 82 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

Type of "STARTUPINFO" is unknown (reportUnknownMemberType)

Check failure on line 82 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

"STARTUPINFO" is not a known member of module "subprocess" (reportAttributeAccessIssue)
env: os._Environ[str] | None # pyright: ignore[reportPrivateUsage]


Expand Down Expand Up @@ -241,15 +241,15 @@
Originally found in https://github.com/madmaze/pytesseract/blob/master/pytesseract/pytesseract.py
Recipe from https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess
which itself is taken from https://github.com/bjones1/enki/blob/master/enki/lib/get_console_output.py
"""
""" # noqa: D415,D400
# The following is true only on Windows.
if hasattr(subprocess, "STARTUPINFO"):
# On Windows, subprocess calls will pop up a command window by default when run from
# Pyinstaller with the ``--noconsole`` option. Avoid this distraction.
startupinfo = subprocess.STARTUPINFO()

Check failure on line 249 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

Type of "startupinfo" is unknown (reportUnknownVariableType)

Check failure on line 249 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

Type of "STARTUPINFO" is unknown (reportUnknownMemberType)

Check failure on line 249 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

"STARTUPINFO" is not a known member of module "subprocess" (reportAttributeAccessIssue)

Check failure on line 249 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

Type of "startupinfo" is unknown (reportUnknownVariableType)

Check failure on line 249 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

Type of "STARTUPINFO" is unknown (reportUnknownMemberType)

Check failure on line 249 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

"STARTUPINFO" is not a known member of module "subprocess" (reportAttributeAccessIssue)
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

Check failure on line 250 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

Type of "dwFlags" is unknown (reportUnknownMemberType)

Check failure on line 250 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

Type of "STARTF_USESHOWWINDOW" is unknown (reportUnknownMemberType)

Check failure on line 250 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

"STARTF_USESHOWWINDOW" is not a known member of module "subprocess" (reportAttributeAccessIssue)

Check failure on line 250 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

Type of "dwFlags" is unknown (reportUnknownMemberType)

Check failure on line 250 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

Type of "STARTF_USESHOWWINDOW" is unknown (reportUnknownMemberType)

Check failure on line 250 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

"STARTF_USESHOWWINDOW" is not a known member of module "subprocess" (reportAttributeAccessIssue)
# https://github.com/madmaze/pytesseract/blob/88839f03590578a10e806a5244704437c9d477da/pytesseract/pytesseract.py#L236
startupinfo.wShowWindow = subprocess.SW_HIDE

Check failure on line 252 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.10)

Type of "SW_HIDE" is unknown (reportUnknownMemberType)

Check failure on line 252 in src/utils.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-22.04, 3.11)

Type of "SW_HIDE" is unknown (reportUnknownMemberType)
# Windows doesn't search the path by default. Pass it an environment so it will.
env = os.environ
else:
Expand Down
Loading