Skip to content

Commit

Permalink
refactoring ocr saving
Browse files Browse the repository at this point in the history
  • Loading branch information
MulongXie committed Aug 5, 2021
1 parent 56a6245 commit 8a52b39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Binary file modified detect_text/__pycache__/text_detection.cpython-35.pyc
Binary file not shown.
10 changes: 5 additions & 5 deletions detect_text/text_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def text_cvt_orc_format(ocr_result):
def text_filter_noise(texts):
valid_texts = []
for text in texts:
if len(text.content) <= 1 and text.content.lower() not in ['a', ',', '.', '!', '?', '$', '%', ':', '&']:
if len(text.content) <= 1 and text.content.lower() not in ['a', ',', '.', '!', '?', '$', '%', ':', '&', '+']:
continue
valid_texts.append(text)
return valid_texts
Expand All @@ -118,17 +118,17 @@ def text_filter_noise(texts):
def text_detection(input_file='../data/input/30800.jpg', output_file='../data/output', show=False):
start = time.clock()
name = input_file.split('/')[-1][:-4]
oct_root = pjoin(output_file, 'ocr')
ocr_root = pjoin(output_file, 'ocr')
img = cv2.imread(input_file)

ocr_result = ocr.ocr_detection_google(input_file)
texts = text_cvt_orc_format(ocr_result)
texts = merge_intersected_texts(texts)
texts = text_filter_noise(texts)
texts = text_sentences_recognition(texts)
visualize_texts(img, texts, shown_resize_height=800, show=show, write_path=pjoin(oct_root, name+'.png'))
save_detection_json(pjoin(oct_root, name+'.json'), texts, img.shape)
print("[Text Detection Completed in %.3f s] %s" % (time.clock() - start, input_file))
visualize_texts(img, texts, shown_resize_height=800, show=show, write_path=pjoin(ocr_root, name+'.png'))
save_detection_json(pjoin(ocr_root, name+'.json'), texts, img.shape)
print("[Text Detection Completed in %.3f s] Input: %s Output: %s" % (time.clock() - start, input_file, pjoin(ocr_root, name+'.json')))


# text_detection()
Expand Down

0 comments on commit 8a52b39

Please sign in to comment.