Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Marie Dev Bot committed May 10, 2024
1 parent 14109ea commit add035e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
1 change: 0 additions & 1 deletion marie/pipe/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ def restore_assets(
:param overwrite: if True, overwrite existing assets in root asset directory
:return:
"""

s3_root_path = s3_asset_path(ref_id, ref_type)
connected = StorageManager.ensure_connection("s3://", silence_exceptions=True)
if not connected:
Expand Down
54 changes: 50 additions & 4 deletions tests/check_qrcode.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
import os
import sys

import cv2
import numpy as np
from pylibdmtx.pylibdmtx import decode

# sudo apt-get install libdmtx0a
filename = "/home/gbugaj/datasets/private/qr-codes/sample-002.png"
image = cv2.imread(filename)
decoded_objects = decode(image)
print(decoded_objects)


def process_data_matrix(filename):
filename = os.path.expanduser(filename)
image = cv2.imread(filename, cv2.IMREAD_UNCHANGED)
if image is None:
print(f"Failed to load image at {filename}")
sys.exit(1)
if len(image.shape) > 2 and image.shape[2] > 1:
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
else:
gray = image

unique_values = np.unique(gray)
if len(unique_values) > 2:
ret, gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

pad = 50
gray = cv2.copyMakeBorder(gray, pad, pad, pad, pad, cv2.BORDER_CONSTANT, value=255)
decoded_objects = decode(gray, corrections=3)

print(decoded_objects)

output = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)
for obj in decoded_objects:
rect = obj.rect
cv2.rectangle(output, (rect.left, rect.top), (rect.left + rect.width, rect.top + rect.height), (0, 0, 255), 2)
# cv2.putText(output, obj.data.decode('utf-8'), (rect.left, rect.top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (0, 0, 255), 1)

center_x = rect.left + rect.width // 2
center_y = rect.top + rect.height // 2

text_size = cv2.getTextSize(obj.data.decode('utf-8'), cv2.FONT_HERSHEY_SIMPLEX, 0.3, 1)[0]

text_x = center_x - text_size[0] // 2
text_y = center_y + text_size[1] // 2
cv2.putText(output, obj.data.decode('utf-8'), (text_x, rect.top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.3,
(0, 0, 255), 1)

cv2.imshow("decoded", output)
cv2.waitKey(0)


if __name__ == '__main__':
filename = "~/datasets/private/qr-codes/code.png"
process_data_matrix(filename)
1 change: 1 addition & 0 deletions tests/integration/check_document_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
def run_extract_pipeline():
MDC.put("request_id", "test")
img_path = "~/tmp/analysis/document-boundary/samples/PID_808_7548_0_202343052.tif"
img_path = "~/dev/workflow/mbx-grapnel/mbx-grapnel-engine/src/test/resources/test-deck/Integration-12079-200687186/PID_3824_11135_0_200687186.tif"
img_path = os.path.expanduser(img_path)
if not os.path.exists(img_path):
raise FileNotFoundError(f"File not found : {img_path}")
Expand Down

0 comments on commit add035e

Please sign in to comment.