Skip to content

Commit

Permalink
修改已知2.0的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cpython666 committed Dec 17, 2023
1 parent 3cb7741 commit 90d2c25
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion output/5996c51c176a374e448190cfe6f69837.txt

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 8 additions & 5 deletions 视频字幕提取-OCR版-2.0.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_video_zimu_imgs(self):
cv2.imencode(".png", new_frame)[1].tofile(image_save_path)
self.progress_zimu_signal.emit(frame_count // frame_interval,total_frames // frame_interval)
# break
# # TODO
# TODO
frame_count += 1

cap.release()
Expand All @@ -96,13 +96,16 @@ def extract_zimu_from_file(self, file):
zimu_width = self.image_width
print(file)
if data:
# print(data)
ocrResult = data['ocrResult']
ocrResult=[i for i in ocrResult if i['location']['right'] and i['location']['left']]
# ocrResult=[i for i in ocrResult if i['location']['right'] and i['location']['left'] and i['location']['top'] and i['location']['bottom']]
if ocrResult:
# 方案一:最宽字幕区间
ocrResult.sort(key=lambda x: -1 * (x['location']['right'] - x['location']['left']))
# 方案二:最高字幕区间
# ocrResult.sort(key=lambda x: (x['location']['top'] - x['location']['bottom']))
# ocrResult.sort(key=lambda x: -1 * (x['location']['right'] - x['location']['left']))
ocrResult=[i for i in ocrResult if i['location']['right'] and i['location']['left'] and i['location']['top'] and i['location']['bottom']]
ocrResult.sort(key=lambda x: -1 * (x['location']['right'] - x['location']['left'])*(x['location']['bottom'] - x['location']['top']))
# 方案三:最大面积
# ocrResult.sort(key=lambda x: -1 * (x['location']['right'] - x['location']['left'])*(x['location']['bottom'] - x['location']['top']))
center = ocrResult[0]['location']['left'] + ocrResult[0]['location']['right']
if abs(center - zimu_width) < 100:
print(ocrResult[0]['text'])
Expand Down

0 comments on commit 90d2c25

Please sign in to comment.