mp-02 commited on
Commit
b4a0c35
·
verified ·
1 Parent(s): 1c11d24

Delete utils.py

Browse files
Files changed (1) hide show
  1. utils.py +0 -40
utils.py DELETED
@@ -1,40 +0,0 @@
1
- from paddleocr import PaddleOCR
2
- from PIL import Image
3
-
4
- def normalize_bbox(bbox, width, height):
5
-
6
- return [
7
- int(1000 * (bbox[0] / width)),
8
- int(1000 * (bbox[1] / height)),
9
- int(1000 * (bbox[2] / width)),
10
- int(1000 * (bbox[3] / height)),
11
- ]
12
-
13
- def unnormalize_box(bbox, width, height):
14
-
15
- return [
16
- width * (bbox[0] / 1000),
17
- height * (bbox[1] / 1000),
18
- width * (bbox[2] / 1000),
19
- height * (bbox[3] / 1000),
20
- ]
21
-
22
-
23
- def OCR(image_path: str):
24
- ocr = PaddleOCR(use_angle_cls=True)
25
- image = Image.open(image_path)
26
- result = ocr.ocr(image_path, cls=True)
27
- bboxes = []
28
- words = []
29
-
30
- for idx in range(len(result)):
31
- res = result[idx]
32
-
33
- for line in res:
34
- # print(line)
35
- # print(line[0][0] + line[0][2])
36
- bboxes.append(normalize_bbox(line[0][0]+line[0][2], image.width, image.height))
37
- # print(line[1][0])
38
- words.append(line[1][0])
39
-
40
- return bboxes, words