Skip to content
Snippets Groups Projects
Commit 40b12da1 authored by Renaud's avatar Renaud
Browse files

Ajout de l'OCR

parent 2c70daac
No related branches found
No related tags found
No related merge requests found
File deleted
File moved
out/biomet_export.jpg

251 KiB

from ._models import Group
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from typing import List, Tuple
from typing import List
class OCR:
"""
......@@ -34,8 +34,7 @@ class OCR:
"""
groups = []
result = self.ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
res = result[idx]
res = result[0]
for line in res:
grp = Group(line[0], line[1][0], line[1][1])
groups.append(grp)
......@@ -49,8 +48,7 @@ class OCR:
boxes = [line.box for line in groups]
txts = [line.string for line in groups]
scores = [line.score for line in groups]
print(image)
im_show = draw_ocr(image, boxes, txts, scores, font_path)
im_show = draw_ocr(image, boxes, txts, scores, font_path=font_path)
im_show = Image.fromarray(im_show)
im_show.save(output_img_path)
return im_show
from tkinter import *
from _models import Dispositif
from ._models import Dispositif
class UI:
"""
......
......@@ -3,16 +3,16 @@ import os
TEST_IMAGES_DIR = "data/img"
OUTPUT_DIR = "out"
FONT_PATH = "baskerville.ttf"
FONT_PATH = "data/font/baskerville.ttf"
def main():
ocr = OCR()
groups1 = ocr.recognize(TEST_IMAGES_DIR + "/biomet.jpg")
groups2 = ocr.recognize(TEST_IMAGES_DIR + "/stryker.jpg")
#groups2 = ocr.recognize(TEST_IMAGES_DIR + "/stryker.jpg")
ocr.save_ocr(groups1, TEST_IMAGES_DIR + "/biomet.jpg", TEST_IMAGES_DIR + "/biomet_export.jpg", os.getcwd() + "\\" + FONT_PATH)
ocr.save_ocr(groups2, TEST_IMAGES_DIR + "/stryker.jpg", TEST_IMAGES_DIR + "/stryker_exports.jpg", os.getcwd() + "\\" + FONT_PATH)
ocr.save_ocr(groups1, TEST_IMAGES_DIR + "/biomet.jpg", OUTPUT_DIR + "/biomet_export.jpg", os.getcwd() + "\\" + FONT_PATH)
#ocr.save_ocr(groups2, TEST_IMAGES_DIR + "/stryker.jpg", TEST_IMAGES_DIR + "/stryker_exports.jpg", os.getcwd() + "\\" + FONT_PATH)
# partie BD : strs = [group.string for group in groups1]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment