好的,我已经通过 OpenCV 运行它:
# function to overlay a transparent image on background.
def transparentOverlay(backgroundImage, overlayImage, pos=(0, 0), scale=1):
overlayImage = cv2.resize(overlayImage, (0, 0), fx=scale, fy=scale)
h, w, _ = overlayImage.shape # Size of foreground
rows, cols, _ = backgroundImage.shape # Size of background Image
y, x = pos[0], pos[1] # Position of foreground/overlayImage image
# loop over all pixels and apply the blending equation
for i in range(h):
for j in range(w):
if x + i >= rows or y + j >= cols:
continue
alpha = float(overlayImage[i][j][3] / 255.0) # read the alpha channel
backgroundImage[x + i][y + j] = alpha * overlayImage[i][j][:3] + (1 - alpha) * backgroundImage[x + i][y + j]
return backgroundImage
然后按如下方式使用:
# Overlay transparent images at desired postion(x,y) and Scale.
result = transparentOverlay(processedImage, shuttleIcon, tuple(trackedCenterPoint), 0.7)
似乎解决了我的问题。