Python OpenCV —— Arithmetic

时间:2023-03-09 19:46:18
Python OpenCV —— Arithmetic

   图案的算术操作。

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 28 11:54:47 2016 @author: Administrator
""" '''
Arithmetic(算术) Operations on Images cv2.add(),cv2addWeighted()
'''
import numpy as np
import 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=>255
print(x+y) # 250+10=260%256 = 4 # Image Blending
# dst = x*img1 + y*img2 + z img1 = 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