首页 > 代码库 > Python OpenCV —— Arithmetic

Python OpenCV —— Arithmetic

   图案的算术操作。

# -*- coding: utf-8 -*-"""Created on Wed Sep 28 11:54:47 2016@author: Administrator"""‘‘‘Arithmetic(算术) Operations on Imagescv2.add(),cv2addWeighted()‘‘‘import numpy as npimport cv2‘‘‘There is a difference between OpenCV addition and Numpy addition.OpenCV addition is a saturated operation while Numpy addition is a modulo operation.‘‘‘x = np.uint8([250])y = np.uint8([10])# 只有超过255时结果才不同print(cv2.add(x,y))  # 250+10=260=>255print(x+y)  # 250+10=260%256 = 4# Image Blending# dst = x*img1 + y*img2 + zimg1 = cv2.imread(‘ml.png‘)img2 = cv2.imread(‘opencv_logo.png‘)# 指定图片大小size = (500, 500)img1 = cv2.resize(img1,size)img2= cv2.resize(img2, size)# 可以理解为,第一个图片占70%的比重,第二个占30%,最后的0,是常数项dst = cv2.addWeighted(img1,0.7,img2,0.3,0)cv2.imshow(‘dst‘,dst)cv2.waitKey(0)cv2.destroyAllWindows()

  输出如下(图丑忽略。。。文档原图未找到):

技术分享

 

Python OpenCV —— Arithmetic