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)
视频加logo代码python opencv-日常工具
最新推荐文章于 2023-11-21 17:07:18 发布