视频帧中放入图片logo opencv

import cv2
import ffmpeg
import cv2
import numpy as np
import glob


video_f = 'D:/.Download/cctv.mp4' # 视频文件名
output_f = 'D:/.Download/logoafter.mp4' # 输出视频文件名
video = cv2.VideoCapture(video_f)
# 获取视频宽度
frame_width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
# 获取视频高度
frame_height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(frame_height,frame_width)
start_x, start_y, w, h = 740,420, 100, 28 # logo位置
logo_f = '1.jpg'
logo = cv2.imread(logo_f)
logo = cv2.resize(logo, (w,h))
print(logo.shape)

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))

idx = 0
while True:
    ret, frame = video.read()
    print(type(frame))
    print(frame.shape)

    idx += 1
    if frame is None:
        break
    if idx > 0 and idx < 1213:
        frame[start_y:start_y + h, start_x:start_x + w, :]=logo

    output_video.write(frame)
    cv2.imshow('f', frame)
    print(idx)
    cv2.waitKey(1)




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值