rogerxavier
commited on
Commit
•
02b7f61
1
Parent(s):
60c10a4
Update 3mergeDialogToVideo.py
Browse files- 3mergeDialogToVideo.py +12 -6
3mergeDialogToVideo.py
CHANGED
@@ -43,7 +43,7 @@ def get_image_copywrite(image_path:"图片路径(包含后缀)",dialog_cut_path:
|
|
43 |
if cur_dialog_texts is not None:
|
44 |
for dialog_text in cur_dialog_texts:
|
45 |
dialog_texts += dialog_text
|
46 |
-
|
47 |
else:
|
48 |
print(dialog_img_path+"识别是空-可能是有问题")
|
49 |
return dialog_texts
|
@@ -97,19 +97,25 @@ def get_sorted_dialog_text(image_path:"包含后缀的文件路径")->"返回排
|
|
97 |
# 按照中心点的坐标从右往左,从上往下的顺序对文本框坐标进行排序
|
98 |
sorted_indices = sorted(range(len(centers)), key=lambda i: (-centers[i][0], centers[i][1]))
|
99 |
|
100 |
-
|
101 |
sorted_coordinates = [boxCoordinates[i] for i in sorted_indices]
|
102 |
sorted_text = [boxInfo['Text'][str(i)] for i in sorted_indices]
|
103 |
|
104 |
-
# 根据x
|
105 |
for i in range(len(sorted_indices) - 1):
|
106 |
if centers[sorted_indices[i]][0] - centers[sorted_indices[i+1]][0] < (sorted_coordinates[i][2][0] - sorted_coordinates[i][0][0]) / 3:
|
107 |
if sorted_coordinates[i][0][1] > sorted_coordinates[i+1][2][1]:
|
|
|
108 |
sorted_indices[i], sorted_indices[i+1] = sorted_indices[i+1], sorted_indices[i]
|
109 |
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
112 |
|
|
|
113 |
print(sorted_coordinates)
|
114 |
print(sorted_text)
|
115 |
return sorted_text
|
@@ -262,7 +268,7 @@ if __name__ == '__main__':
|
|
262 |
|
263 |
##获取当前图片对应的对话框识别文字(还需gpt处理后作为字幕文案)
|
264 |
cur_copywrite = get_image_copywrite(image_file,dialog_img_path) # image_file就是6.jpg了
|
265 |
-
cur_copywrite = gpt_polish(cur_copywrite)
|
266 |
|
267 |
|
268 |
|
|
|
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+"识别是空-可能是有问题")
|
49 |
return dialog_texts
|
|
|
97 |
# 按照中心点的坐标从右往左,从上往下的顺序对文本框坐标进行排序
|
98 |
sorted_indices = sorted(range(len(centers)), key=lambda i: (-centers[i][0], centers[i][1]))
|
99 |
|
100 |
+
# 获取排序后的文本框坐标和对应的文字
|
101 |
sorted_coordinates = [boxCoordinates[i] for i in sorted_indices]
|
102 |
sorted_text = [boxInfo['Text'][str(i)] for i in sorted_indices]
|
103 |
|
104 |
+
# 根据x方向偏差对小于1/3宽度之间的不同文本框进行重排
|
105 |
for i in range(len(sorted_indices) - 1):
|
106 |
if centers[sorted_indices[i]][0] - centers[sorted_indices[i+1]][0] < (sorted_coordinates[i][2][0] - sorted_coordinates[i][0][0]) / 3:
|
107 |
if sorted_coordinates[i][0][1] > sorted_coordinates[i+1][2][1]:
|
108 |
+
#if这里看y轴了
|
109 |
sorted_indices[i], sorted_indices[i+1] = sorted_indices[i+1], sorted_indices[i]
|
110 |
|
111 |
+
# 根据x方向和文本框宽度对大于一个标准宽度之间的不同文本框断句
|
112 |
+
for i in range(len(sorted_indices) - 1):
|
113 |
+
if centers[sorted_indices[i]][0] - centers[sorted_indices[i + 1]][0] > (
|
114 |
+
sorted_coordinates[i][2][0] - sorted_coordinates[i][0][0]) * 1.5:
|
115 |
+
# 如果相邻文本框的横坐标距离大于一个标准宽度的2/3,进行断句
|
116 |
+
sorted_text[i] += '\n'
|
117 |
|
118 |
+
sorted_coordinates = [boxCoordinates[i] for i in sorted_indices]
|
119 |
print(sorted_coordinates)
|
120 |
print(sorted_text)
|
121 |
return sorted_text
|
|
|
268 |
|
269 |
##获取当前图片对应的对话框识别文字(还需gpt处理后作为字幕文案)
|
270 |
cur_copywrite = get_image_copywrite(image_file,dialog_img_path) # image_file就是6.jpg了
|
271 |
+
#cur_copywrite = gpt_polish(cur_copywrite)#不用gpt,只用新版漫画块得到的100%识别原文即可
|
272 |
|
273 |
|
274 |
|