首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。