Skip to content

Commit

Permalink
fix vendor detection
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 committed Dec 29, 2023
1 parent 80ac4e4 commit e1c493a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/scripts/vision_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def reset_canvas(root, canvas):

def is_vendor_open(img: np.ndarray):
cropped = crop(img, Config().ui_roi["vendor_text"])
res = image_to_text(cropped)
res = image_to_text(cropped, do_pre_proc=False)
return res.text.strip().lower() == "vendor"


Expand Down
9 changes: 6 additions & 3 deletions src/utils/ocr/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _img_to_bytes(image: np.ndarray, colorspace: str = "BGR"):
return image.tobytes(), width, height, bytes_per_pixel, bytes_per_line


def image_to_text(img: np.ndarray, line_boxes: bool = False) -> OcrResult | tuple[OcrResult, list[int]]:
def image_to_text(img: np.ndarray, line_boxes: bool = False, do_pre_proc: bool = True) -> OcrResult | tuple[OcrResult, list[int]]:
"""
Extract text from the entire image.
:param img: The input image.
Expand All @@ -59,8 +59,11 @@ def image_to_text(img: np.ndarray, line_boxes: bool = False) -> OcrResult | tupl
:param scale: The scaling factor for the image.
:return: The OCR result.
"""
pre_proced_img = pre_proc_img(img)
API.SetImageBytes(*_img_to_bytes(pre_proced_img))
if do_pre_proc:
pre_proced_img = pre_proc_img(img)
API.SetImageBytes(*_img_to_bytes(pre_proced_img))
else:
API.SetImageBytes(*_img_to_bytes(img))
start = time.time()
text = API.GetUTF8Text().strip()
# print(f"Get Text: {time.time() - start}")
Expand Down

0 comments on commit e1c493a

Please sign in to comment.