python opencv圖像融合

# -*- coding: utf-8 -*-

import numpy as np
from matplotlib import pyplot as plt
import cv2

def addWeight():
	pic1 = 'F:\\dataSet\\picture\\000006 (2).jpg'
	pic2 = 'F:\\dataSet\\picture\\1.png'
	
	img1=cv2.imread(pic1)
	img2=cv2.imread(pic2)
	
	maxHight = min(img1.shape[0], img2.shape[0])
	maxWidth = min(img1.shape[1], img2.shape[1])
	img1_roi = img1[0:maxHight, 0:maxWidth]
	img2_roi = img2[0:maxHight, 0:maxWidth]
	
	cv2.imshow('img1', img1)
	cv2.imshow('img2', img2)
	
	listw = [x/100 for x in range(101)]
	
	flag = True
	isStop = False
	while not isStop:
		if flag:
			for w in listw:
				dst=cv2.addWeighted(img1_roi,(1- w), img2_roi,w, 0)
				cv2.imshow('dst',dst)
				key = cv2.waitKey(30) &0xFF
				if key == 27:
					isStop = True
			flag = not flag
		else:
			for w in listw:
				dst=cv2.addWeighted(img1_roi, w, img2_roi, 1- w, 0)
				cv2.imshow('dst',dst)
				key = cv2.waitKey(30) &0xFF
				if key == 27:
					isStop = True
			flag = not flag
	
	cv2.waitKey(0)
	cv2.destroyAllWindows()

def main():
	x = np.uint8([250])
	y = np.uint8([10])
	print(cv2.add(x, y))
	print(x + y)
	
	addWeight()

if __name__ == '__main__':
	main()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章