rogerxavier
commited on
Commit
•
3b99f69
1
Parent(s):
a046690
Update 3mergeDialogToVideo.py
Browse files- 3mergeDialogToVideo.py +12 -2
3mergeDialogToVideo.py
CHANGED
@@ -9,7 +9,7 @@ import requests
|
|
9 |
|
10 |
import tempfile
|
11 |
import time
|
12 |
-
|
13 |
from moviepy.audio.AudioClip import AudioArrayClip
|
14 |
from moviepy.editor import *
|
15 |
import cv2
|
@@ -34,6 +34,15 @@ print("my_openai_key",my_openai_key)
|
|
34 |
|
35 |
#通过去水印完整漫画图片->获取相应的对话框图片->获取对话框文字->返回对话框文字
|
36 |
def get_image_copywrite(image_path:"图片路径(包含后缀)",dialog_cut_path:"对话框切割路径")->"返回漫画关联对话框识别后得到的文案str(原文即可),也可能是none":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
dialog_texts = ''
|
38 |
associate_dialog_img = get_associate_dialog(image_path=image_path,dialog_cut_path=dialog_cut_path)
|
39 |
if len(associate_dialog_img)!=0:
|
@@ -42,7 +51,8 @@ def get_image_copywrite(image_path:"图片路径(包含后缀)",dialog_cut_path:
|
|
42 |
cur_dialog_texts = get_sorted_dialog_text(dialog_img_path)#一个对话框的文字list
|
43 |
if cur_dialog_texts is not None:
|
44 |
for dialog_text in cur_dialog_texts:
|
45 |
-
dialog_texts += dialog_text
|
|
|
46 |
#因为已经在数组中加入了\n 换行,这里就不用加了
|
47 |
else:
|
48 |
print(dialog_img_path+"识别是空-可能是有问题")
|
|
|
9 |
|
10 |
import tempfile
|
11 |
import time
|
12 |
+
import re #正则对话剔除非中文,保留'\n'
|
13 |
from moviepy.audio.AudioClip import AudioArrayClip
|
14 |
from moviepy.editor import *
|
15 |
import cv2
|
|
|
34 |
|
35 |
#通过去水印完整漫画图片->获取相应的对话框图片->获取对话框文字->返回对话框文字
|
36 |
def get_image_copywrite(image_path:"图片路径(包含后缀)",dialog_cut_path:"对话框切割路径")->"返回漫画关联对话框识别后得到的文案str(原文即可),也可能是none":
|
37 |
+
def extract_chinese(text:str)->str:
|
38 |
+
#剔除除了 '\n'外的非中文字符
|
39 |
+
chinese_pattern = re.compile("[\u4e00-\u9fa5]+") # 匹配中文字符的正则表达式
|
40 |
+
chinese_text = ""
|
41 |
+
for char in text:
|
42 |
+
if char == '\n' or re.match(chinese_pattern, char):
|
43 |
+
chinese_text += char
|
44 |
+
return chinese_text
|
45 |
+
|
46 |
dialog_texts = ''
|
47 |
associate_dialog_img = get_associate_dialog(image_path=image_path,dialog_cut_path=dialog_cut_path)
|
48 |
if len(associate_dialog_img)!=0:
|
|
|
51 |
cur_dialog_texts = get_sorted_dialog_text(dialog_img_path)#一个对话框的文字list
|
52 |
if cur_dialog_texts is not None:
|
53 |
for dialog_text in cur_dialog_texts:
|
54 |
+
# dialog_texts += dialog_text
|
55 |
+
dialog_texts += extract_chinese(dialog_text)
|
56 |
#因为已经在数组中加入了\n 换行,这里就不用加了
|
57 |
else:
|
58 |
print(dialog_img_path+"识别是空-可能是有问题")
|