OpenCV-Python小白进阶之图片的融合

OpenCV-Python小白进阶之图片的融合

方法

cv2.resize()

https://wgowi.github.io/2019/08/18/OpenCV-Python%E5%B0%8F%E7%99%BD%E8%BF%9B%E9%98%B6%E4%B9%8B%E5%9B%BE%E7%89%87%E7%9A%84%E4%BC%B8%E7%BC%A9%E5%8F%98%E6%8D%A2/#more

cv2.addWeighted(img1, x, img2, y, 0)

把img1与img2按xy的比重融合

cv2.add(img1,img2)

将img1与img2按1:1融合

代码实现

import cv2

img1 = cv2.imread('a.jpg')
img2 = cv2.imread('cv.jpg')

img3 = cv2.resize(img1, (400, 400))
img4 = cv2.resize(img2, (400, 400))

img5 = cv2.addWeighted(img3, 0.5, img4, 0.5, 0)
img6 = cv2.add(img3,img4)
img7 = cv2.addWeighted(img4, 1, img3, 1, 0)

cv2.imshow('img5', img5)
cv2.imshow('img6', img6)
cv2.imshow('img7', img7)

while True:
    if cv2.waitKey(1) == 27:
        break
cv2.destroyAllWindows()

OpenCV-Python小白进阶之图片的融合_第1张图片
OpenCV-Python小白进阶之图片的融合_第2张图片
OpenCV-Python小白进阶之图片的融合_第3张图片
由此可知cv2.addweighted()img1和img2的比重都为1时与cv2.add()相同

你可能感兴趣的:(OpenCV)