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

[IDWA-OCR-72] Install OCR into an executable #73

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Binary file added OCR/ocr/assets/form_segmention_template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions OCR/ocr/assets/labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
Copy link
Collaborator Author

@derekadombek derekadombek Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied these into the main service directory as well but not necessarily sure how I feel about these being in two different places even though I know they might not even be located in the repo in the future anyways but if we do want to only use them from the og test directory ATM, I will need to move the pyinstaller.py function to the root dir.

Copy link
Collaborator Author

@derekadombek derekadombek Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to this, I tried moving the pyinstaller.py to the root OCR directory just to try it without needing the duplicate asset files and it would not work properly ATM with how we ingesting the asset files from the local directories and cannot backout of paths(ie. ..) like we currently are doing with the tests/ directory. So the best way to use this right now for running main.py with or without an executable is to put separate assets in the ocr dir.

"255,0,0": "nbs_patient_id",
"0,0,255": "nbs_cas_id"
}
12 changes: 9 additions & 3 deletions OCR/ocr/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

from ocr.services.image_segmenter import ImageSegmenter
from ocr.services.image_ocr import ImageOCR
Expand All @@ -9,10 +10,15 @@
def main():

segmentation_template = os.path.join(
path, "../tests/assets/form_segmention_template.png"
path, "assets/form_segmention_template.png"
)
raw_image = os.path.join(path, "../tests/assets/form_filled.png")
labels_path = os.path.join(path, "../tests/assets/labels.json")
# I think this could be an area to enhance later on with a more fleshed out CLI
if sys.argv[1] is None:
raw_image = os.path.join(path, "assets/form_filled.png")
elif sys.argv[1] is not None:
raw_image = sys.argv[1]

labels_path = os.path.join(path, "assets/labels.json")

segmenter = ImageSegmenter(raw_image, segmentation_template, labels_path)
segments = segmenter.segment()
Expand Down
18 changes: 18 additions & 0 deletions OCR/ocr/pyinstaller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import PyInstaller.__main__
from pathlib import Path

HERE = Path(__file__).parent.absolute()
path_to_main = str(HERE / "main.py")

#This function installs/packages the main OCR function as an executable
#while also including the needed assets ie. the mapping labels and segmentation template
def install():
PyInstaller.__main__.run([
path_to_main,
'--onefile',
'--windowed',
# SOURCE:DESTINATION
'--add-data=ocr/assets/form_segmention_template.png:assets/',
'--add-data=ocr/assets/labels.json:assets/',
# other pyinstaller options...
])
1 change: 1 addition & 0 deletions OCR/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
main = "ocr.main:main"
build = "ocr.pyinstaller:install"