視頻加logo代碼python opencv-日常工具

import cv2
import numpy as np
import glob


video_f = 'demo_20200408_38.mp4' # 視頻文件名
output_f = 'demo_20200408_38_logo.avi' # 輸出視頻文件名
video = cv2.VideoCapture(video_f)
logo_f = 'LOGO豎版彩色.png‘ # 需要加的logo
start_x, start_y, w, h = 50,50, 100, 125 # logo位置
logo = cv2.imread(logo_f)
logo = cv2.cvtColor(logo, cv2.COLOR_BGR2GRAY)
logo = cv2.resize(logo, (w,h))
ret, frame = video.read()
img_h, img_w = frame.shape[:2]
output_video = cv2.VideoWriter(output_f, cv2.VideoWriter_fourcc(*'DIV3'), 30, (img_w, img_h))
logo[logo<254] = 0  
idx = 0
while True:
    ret, frame = video.read()
    idx += 1
    if frame is None:
        break    
    # frame[start_y:start_y+h, start_x:start_x+w,:] = 0
    if idx > 65 and idx < 1670:
    	frame[start_y:start_y+h, start_x:start_x+w,:][logo==0] = 255
    output_video.write(frame)
    cv2.imshow('f', frame)
    print(idx)
    cv2.waitKey(1)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章