Python OpenCV —— Arithmetic

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

python opencv安装问题?

python怎么安装opencv库

Python-OpenCV学习:OpenCV结构

如何在mac上安装opencv与python

OpenCV training program, part 2: OpenCV-Python Tutorials

opencv-python