Commit eb8368db authored by 翟艳秋(20软)'s avatar 翟艳秋(20软)

modified: no need to change the startTime

parent 148178b6
import os import os
# import time
import cv2 import cv2
import numpy as np import numpy as np
...@@ -28,6 +27,8 @@ def get_position(video_path, start_time): ...@@ -28,6 +27,8 @@ def get_position(video_path, start_time):
video = cv2.VideoCapture(video_path) video = cv2.VideoCapture(video_path)
subtitle_position = {} subtitle_position = {}
fps = video.get(cv2.CAP_PROP_FPS) fps = video.get(cv2.CAP_PROP_FPS)
if video.get(cv2.CAP_PROP_FRAME_COUNT) / fps > 10 * 60:
start_time = start_time + 300
start = int(start_time * fps) start = int(start_time * fps)
cnt = 0 cnt = 0
txt_cnt = 0 txt_cnt = 0
...@@ -139,7 +140,8 @@ def detect_subtitle(img): ...@@ -139,7 +140,8 @@ def detect_subtitle(img):
:return: [str|None], 字幕信息 :return: [str|None], 字幕信息
""" """
subTitle = '' subTitle = ''
img = img[int(up_b) - 30:int(down_b) + 30] height = down_b - up_b
img = img[int(up_b - height * 0.6):int(down_b + height * 0.6)]
# img = cv2.resize(img, (int(img.shape[1] * 0.5), int(img.shape[0] * 0.5))) # img = cv2.resize(img, (int(img.shape[1] * 0.5), int(img.shape[0] * 0.5)))
res = ocr.ocr(img, cls=True) res = ocr.ocr(img, cls=True)
sorted(res, key=lambda text: text[0][0][1]) sorted(res, key=lambda text: text[0][0][1])
...@@ -264,7 +266,7 @@ def detect_with_ocr(video_path, book_path, start_time, end_time, state): ...@@ -264,7 +266,7 @@ def detect_with_ocr(video_path, book_path, start_time, end_time, state):
# 获取字幕在画面中的上下边界,方便在后续视频遍历过程中直接对字幕对应区域进行分析 # 获取字幕在画面中的上下边界,方便在后续视频遍历过程中直接对字幕对应区域进行分析
global up_b, down_b global up_b, down_b
up_b, down_b = get_position(video_path, start_time + 30) up_b, down_b = get_position(video_path, start_time)
# 获取并构建输出信息 # 获取并构建输出信息
table_head = [["起始时间", "终止时间", "字幕", '建议', '解说脚本']] table_head = [["起始时间", "终止时间", "字幕", '建议', '解说脚本']]
......
...@@ -73,10 +73,10 @@ class RunThread(threading.Thread): ...@@ -73,10 +73,10 @@ class RunThread(threading.Thread):
try: try:
self._run() self._run()
except Exception as e: except Exception as e:
print(e)
self.exitcode = 1 # 如果线程异常退出,将该标志位设置为1,正常退出为0 self.exitcode = 1 # 如果线程异常退出,将该标志位设置为1,正常退出为0
self.exception = e self.exception = e
self.exc_traceback = ''.join(traceback.format_exception(*sys.exc_info())) # 在改成员变量中记录异常信息 self.exc_traceback = ''.join(traceback.format_exception(*sys.exc_info())) # 在改成员变量中记录异常信息
print(self.exc_traceback)
def _run(self): def _run(self):
"""运行函数,并合理抛出异常 """运行函数,并合理抛出异常
...@@ -257,7 +257,7 @@ def start_detect(): ...@@ -257,7 +257,7 @@ def start_detect():
# 多线程同步进行检测和进度条更新 # 多线程同步进行检测和进度条更新
state = [None] state = [None]
threads = [] threads = []
t = RunThread(funcName=start_process, args=(progressbar_1, progress_1, state, 100000), name="startProgress1") t = RunThread(funcName=start_process, args=(progressbar_1, progress_1, state, 300000), name="startProgress1")
t.setDaemon(True) t.setDaemon(True)
threads.append(t) threads.append(t)
t = RunThread(funcName=detect, t = RunThread(funcName=detect,
...@@ -458,7 +458,7 @@ def start_synthesis(): ...@@ -458,7 +458,7 @@ def start_synthesis():
args=(video_path, sheet_path, audio_dir, speed, caption_path, state), name="ssAndExport") args=(video_path, sheet_path, audio_dir, speed, caption_path, state), name="ssAndExport")
t.setDaemon(True) t.setDaemon(True)
threads.append(t) threads.append(t)
t = RunThread(funcName=start_process, args=(progressbar_2, progress_2, state, 100000), name="startProgress2") t = RunThread(funcName=start_process, args=(progressbar_2, progress_2, state, 300000), name="startProgress2")
t.setDaemon(True) t.setDaemon(True)
threads.append(t) threads.append(t)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment