0
点赞
收藏
分享

微信扫一扫

opencv--字幕-非眩光(圆心亮点)实验

前行的跋涉者 2022-04-17 阅读 23
python
#从网上下载或自己手机录制一段视频(>30秒),第0-5秒显示一句话的字幕,第6-15秒显示另一句话的字幕。
#第20秒开始从屏幕中心出现一个光点,发出眩光,逐渐扩大覆盖的整个屏幕(类似太阳),最后光点缩小复原,整个过程10秒。
#
#从网上下载或自己手机录制一段视频(>30秒),第0-5秒显示一句话的字幕,第6-15秒显示另一句话的字幕。
#第20秒开始从屏幕中心出现一个光点,发出眩光,逐渐扩大覆盖的整个屏幕(类似太阳),最后光点缩小复原,整个过程10秒。这个没有实现好
#

import cv2

def white_circle(img,radius):
    cv2.circle(img,(447,63),63,(0,0,255),-1)

#original_video
org_video = "../data/LawerCrush.mp4"
#video_subtitled
sub_video = "../data/LawerCrush_subtitles1.mp4"
#read video
Video = cv2.VideoCapture(org_video)
#Gets the video frame rate
Fps_video = Video.get(cv2.CAP_PROP_FPS)
#Sets the encoding format for writing video
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
#Get video width
frame_width = int(Video.get(cv2.CAP_PROP_FRAME_WIDTH))
#Get video Height
frame_height = int(Video.get(cv2.CAP_PROP_FRAME_HEIGHT))
#Save the video after the subtitles
videoWriter = cv2.VideoWriter(sub_video, fourcc, Fps_video, (frame_width, frame_height))

##Add subtitles
glare_time = int(Fps_video*5)-1 #vanish overflow
glare_count = 0
frame_id = 0
w_index = 0
putword = ['He is a down-and-out lawyer','God gave him another surprise','  ']
cc_x = int(frame_width/2)
cc_y = int(frame_height/2)
while (Video.isOpened()):
    ret, frame = Video.read()
    if ret == True:
        frame_id += 1
        time_s = int(frame_id/Fps_video)
        if(time_s<6):
            w_index = 0
        elif(time_s<16):
            w_index = 1
        else:
            w_index =2
            if 20<time_s <= 25 :
                glare_count += 1
            elif 25< time_s <=30:
                glare_count -= 1
            cv2.circle(frame,(cc_x,cc_y),int((cc_y/glare_time)*glare_count),(255,255,255),-1)
    #Text coordinates
        word_x = 450
        word_y = int(frame_height)-18
        cv2.putText(frame, '%s' %putword[w_index], (word_x, word_y), cv2.FONT_HERSHEY_SIMPLEX, 2, (255,255,255), 2)

        #****写入视频
        videoWriter.write(frame)
    else:
        videoWriter.release()
        break
举报

相关推荐

0 条评论