虚拟广告牌是体育广播中常用的一种广告形式。这些广告牌不是真的,会被面前移动的物体覆盖,就像它就在那里一样。我想知道有没有可能通过python实现这一点?采取
this video
举个例子。(您可以通过
this
将其添加到车道将如下所示:
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)
这给了我:
但是,如果我在每个视频帧上都这样做,黄色区域将只覆盖经过它的车辆,而不是被车辆覆盖。我怎样才能使它像一个虚拟的广告牌,它将被视频中移动的物体所覆盖?