python - 如何使用 python 在视频中添加虚拟广告牌之类的东西
问题描述
虚拟广告牌常用于体育转播。这些广告牌不是真实的,它们会被它们面前的移动物体所覆盖,就像它就在那里一样。我想知道是否可以通过python做到这一点?以这个视频为例。(你可以通过这个下载它。)我们可以在车道上方但在车辆下方添加一些东西吗?让我们说这个简单的黄色矩形:
将其添加到车道将是这样的:
当车辆经过这个黄色区域时,该区域应该被车辆覆盖而不是覆盖车辆。
在处理视频之前,我正在尝试首先使用单应性和一些包装将矩形添加到图片中并使用以下代码拟合图片中的车道区域:
import cv2
import numpy as np
# source image
source_img = cv2.imread('yellow_rec.jpg')
size = source_img.shape
# get four corners of the source (clock wise)
pts_source = np.array(
[
[0,0],
[size[1] - 1, 0],
[size[1] - 1, size[0] -1],
[0, size[0] - 1 ]
],dtype=float
)
#pts_source = np.array([[310,0], [440,0], [589,151],[383,151]])
# destination image
dst_img = cv2.imread('video_screen_shot.png')
# four corners in destination image (also clock wise):
pts_dst = np.array([[400,115], [531,108], [647,186],[533,244]])
# calculate homography
h, status = cv2.findHomography(pts_source, pts_dst)
# warp source image to destination based on homography
temp = cv2.warpPerspective(source_img, h, (dst_img.shape[1], dst_img.shape[0]))
# Black out polygonal area in destination image.
cv2.fillConvexPoly(dst_img, pts_dst.astype(int), 0, 16)
# Add warped source image to destination image.
dst_img = dst_img + temp
cv2.imshow('warpped', dst_img)
cv2.waitKey(0)
但是,如果我在每个视频帧上都这样做,黄色区域只会覆盖经过它的车辆,而不是被车辆覆盖。我怎样才能让它像一个虚拟广告牌,被视频中的移动物体覆盖?
解决方案
推荐阅读
- excel - 对整列运行宏
- c - C 编程 - 过滤数组
- probability - 通过反应堆屏蔽的中子
- flutter - 列出附近开启蓝牙的手机(flutter_blue 包)
- javascript - 仍在为此苦苦挣扎...为什么我不能在鼠标移出工作时淡出?
- javascript - 对象中定义的 JS 函数范围不适用于代码覆盖
- javascript - 如何在动态添加行和单元格的表格中拖放单元格内容?
- c++ - 复制矢量
缓冲区到帧缓冲区 - azure - Azure SAML SSO 唯一用户标识符在响应中不正确
- mysql - LDAP 连接超时错误(带有后端 MySQL 的 OpenLDAP)