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

[bug fix] fix none res in recovery #10603

Merged
merged 26 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38f2601
add finetune en doc & test=document_fix
andyjiang1116 Nov 30, 2022
a53ea42
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Dec 5, 2022
8ace87b
fix dead link & test=document_fix
andyjiang1116 Dec 5, 2022
957c0b3
fix dead link & test=document_fix
andyjiang1116 Dec 5, 2022
514ed2b
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Dec 6, 2022
c0f4555
update check img
andyjiang1116 Dec 6, 2022
3423229
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Dec 14, 2022
d5e9f77
fix det res dtype
andyjiang1116 Dec 14, 2022
b3dbc15
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Jan 11, 2023
7fc3539
update args default type & test=document_fix
andyjiang1116 Jan 11, 2023
8fd8cbc
fix numpy version
andyjiang1116 Jan 30, 2023
1b1d0b1
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Jan 30, 2023
729fbe0
support numpy1.24.0
andyjiang1116 Jan 30, 2023
68af5d1
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Feb 15, 2023
9e4cca5
fix doc & test=document_fix
andyjiang1116 Feb 23, 2023
818083c
update doc
andyjiang1116 Mar 28, 2023
bd39ee9
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Mar 28, 2023
5eebc3c
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Aug 7, 2023
76daf47
update doc, test=document_fix
andyjiang1116 Aug 7, 2023
7e7ac52
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Aug 7, 2023
62bd53c
fix pdf2word in whl, test=document_fix
andyjiang1116 Aug 9, 2023
7380894
fix none res in recovery
andyjiang1116 Aug 10, 2023
3dc8a57
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Aug 10, 2023
5255242
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
andyjiang1116 Aug 10, 2023
6494be6
update version
andyjiang1116 Aug 10, 2023
2f3d278
format code
andyjiang1116 Aug 10, 2023
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
2 changes: 1 addition & 1 deletion paddleocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _import_file(module_name, file_path, make_importable=False):
]

SUPPORT_DET_MODEL = ['DB']
VERSION = '2.7.0.1'
VERSION = '2.7.0.2'
SUPPORT_REC_MODEL = ['CRNN', 'SVTR_LCNet']
BASE_DIR = os.path.expanduser("~/.paddleocr/")

Expand Down
2 changes: 2 additions & 0 deletions ppstructure/recovery/recovery_to_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def convert_info_docx(img, res, save_folder, img_name):

flag = 1
for i, region in enumerate(res):
if len(region['res']) == 0:
continue
img_idx = region['img_idx']
if flag == 2 and region['layout'] == 'single':
section = doc.add_section(WD_SECTION.CONTINUOUS)
Expand Down
44 changes: 24 additions & 20 deletions ppstructure/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
import PIL
from PIL import Image, ImageDraw, ImageFont
import numpy as np
<<<<<<< HEAD
from tools.infer.utility import draw_ocr_box_txt, str2bool, init_args as infer_args

=======
from tools.infer.utility import draw_ocr_box_txt, str2bool, str2int_tuple, init_args as infer_args
import math
>>>>>>> 1e11f254 (CV套件建设专项活动 - 文字识别返回单字识别坐标 (#10515))


def init_args():
parser = infer_args()
Expand Down Expand Up @@ -138,7 +134,7 @@ def draw_structure_result(image, result, font_path):
[(box_layout[0], box_layout[1]), (box_layout[2], box_layout[3])],
outline=box_color,
width=3)

if int(PIL.__version__.split('.')[0]) < 10:
text_w, text_h = font.getsize(region['type'])
else:
Expand Down Expand Up @@ -167,9 +163,11 @@ def draw_structure_result(image, result, font_path):
for word_region in text_result['text_word_region']:
char_box = word_region
box_height = int(
math.sqrt((char_box[0][0] - char_box[3][0])**2 + (char_box[0][1] - char_box[3][1])**2))
math.sqrt((char_box[0][0] - char_box[3][0])**2 + (
char_box[0][1] - char_box[3][1])**2))
box_width = int(
math.sqrt((char_box[0][0] - char_box[1][0])**2 + (char_box[0][1] - char_box[1][1])**2))
math.sqrt((char_box[0][0] - char_box[1][0])**2 + (
char_box[0][1] - char_box[1][1])**2))
if box_height == 0 or box_width == 0:
continue
boxes.append(word_region)
Expand All @@ -180,17 +178,18 @@ def draw_structure_result(image, result, font_path):
img_layout, boxes, txts, scores, font_path=font_path, drop_score=0)
return im_show


def cal_ocr_word_box(rec_str, box, rec_word_info):
''' Calculate the detection frame for each word based on the results of recognition and detection of ocr'''

col_num, word_list, word_col_list, state_list = rec_word_info
box = box.tolist()
bbox_x_start = box[0][0]
bbox_x_end = box[1][0]
bbox_y_start = box[0][1]
bbox_y_end = box[2][1]

cell_width = (bbox_x_end - bbox_x_start)/col_num
cell_width = (bbox_x_end - bbox_x_start) / col_num

word_box_list = []
word_box_content_list = []
Expand All @@ -200,26 +199,31 @@ def cal_ocr_word_box(rec_str, box, rec_word_info):
if state == 'cn':
if len(word_col) != 1:
char_seq_length = (word_col[-1] - word_col[0] + 1) * cell_width
char_width = char_seq_length/(len(word_col)-1)
char_width = char_seq_length / (len(word_col) - 1)
cn_width_list.append(char_width)
cn_col_list += word_col
word_box_content_list += word
else:
cell_x_start = bbox_x_start + int(word_col[0] * cell_width)
cell_x_end = bbox_x_start + int((word_col[-1]+1) * cell_width)
cell = ((cell_x_start, bbox_y_start), (cell_x_end, bbox_y_start), (cell_x_end, bbox_y_end), (cell_x_start, bbox_y_end))
cell_x_end = bbox_x_start + int((word_col[-1] + 1) * cell_width)
cell = ((cell_x_start, bbox_y_start), (cell_x_end, bbox_y_start),
(cell_x_end, bbox_y_end), (cell_x_start, bbox_y_end))
word_box_list.append(cell)
word_box_content_list.append("".join(word))
if len(cn_col_list) != 0:
if len(cn_width_list) != 0:
avg_char_width = np.mean(cn_width_list)
else:
avg_char_width = (bbox_x_end - bbox_x_start)/len(rec_str)
avg_char_width = (bbox_x_end - bbox_x_start) / len(rec_str)
for center_idx in cn_col_list:
center_x = (center_idx+0.5)*cell_width
cell_x_start = max(int(center_x - avg_char_width/2), 0) + bbox_x_start
cell_x_end = min(int(center_x + avg_char_width/2), bbox_x_end-bbox_x_start) + bbox_x_start
cell = ((cell_x_start, bbox_y_start), (cell_x_end, bbox_y_start), (cell_x_end, bbox_y_end), (cell_x_start, bbox_y_end))
center_x = (center_idx + 0.5) * cell_width
cell_x_start = max(int(center_x - avg_char_width / 2),
0) + bbox_x_start
cell_x_end = min(
int(center_x + avg_char_width / 2), bbox_x_end -
bbox_x_start) + bbox_x_start
cell = ((cell_x_start, bbox_y_start), (cell_x_end, bbox_y_start),
(cell_x_end, bbox_y_end), (cell_x_start, bbox_y_end))
word_box_list.append(cell)
return word_box_content_list, word_box_list

return word_box_content_list, word_box_list