python - 有快速合成两张图片的功能吗?
问题描述
我正在寻找一种在 Python 或 Cpython 中以最快的方式(0.01s at 1920x1080)合成两个图像的解决方案。
这是一个例子:
前景图像需要在正确的位置。
这是我的慢代码:
def alpha_composite(self, im, dest=(0, 0)):
""" 'In-place' analog of Image.alpha_composite. Composites an image
onto this image.
:param im: image to composite over this one
:param dest: Optional 2 tuple (left, top) specifying the upper
left corner in this (destination) image.
Performance Note: Not currently implemented in-place in the core layer.
"""
(w, h) = self.size
(wH, wW) = im._instance.shape[:2]
(B, G, R, A) = cv2.split(im._instance)
B = cv2.bitwise_and(B, B, mask=A)
G = cv2.bitwise_and(G, G, mask=A)
R = cv2.bitwise_and(R, R, mask=A)
im._instance = cv2.merge([B, G, R, A])
overlay = np.zeros((h, w, 4), dtype=np.float32)
overlay[dest[1]:wH + dest[1], dest[0]:wW + dest[0]] = im._instance
cv2.addWeighted(overlay.astype(np.float32), 0.4, self._instance.astype(
np.float32), 1.0, 0, self._instance.astype(np.float32))
解决方案
推荐阅读
- python-3.x - 使用 Stack Python 进行括号检查
- laravel - Laravel URL 变为 localhost/index.php/login 。如何将其更改回本地主机/登录名?
- javascript - 如何以角度显示数组内部的数组数据
- flutter - 使用提供程序删除和添加列表项时如何更新 UI
- pytorch - Skorch RuntimeError:输入类型(torch.cuda.ByteTensor)和权重类型(torch.cuda.FloatTensor)应该相同
- excel - 将图像和数据从多个源工作簿复制到单个工作簿的有效方法
- swift - TableView 显示相同的数组过滤元素,即使数组元素未过滤
- sas - 创建 SAS 宏以查找指定窗口的开始月份和年份
- clojure - Clojure:如何获取符号的 *value* 作为关键字
- c# - 如何以编程方式在 Unity2D 中切换瓷砖调色板