# coding=utf-8
"""
功能:基于 OpenCV 的图像融合
步骤:
1. 图像导入
2. 调整图像大小
3. 融合图像
4. 导出结果
@author: libo
"""
import cv2
bg = cv2.imread('./images/backgound.jpg', cv2.IMREAD_COLOR)
fg = cv2.imread('./images/foreground.jpg', cv2.IMREAD_COLOR)
dim = (1200, 800)
resize_bg = cv2.resize(bg, dim, interpolation=cv2.INTER_AREA)
resize_fg = cv2.resize(fg, dim, interpolation=cv2.INTER_AREA)
""" addWeighted 函数说明:
五个参数:(每个图像的权重必须小于1)
1. 图像源 1
2. src1 权重
3. 图像源 2
4. src2 权重
5. 伽玛
混合方程:通过调整参数,使得背景更暗,文本更亮
blend = src1 * src1_weight + src2 * src2_weight + gamma
"""
blend = cv2.addWeighted(resize_bg, 0.5, resize_fg, 0.8, 0.0)
cv2.imwrite('./images/blend.png', blend)