码迷,mamicode.com
首页 > 编程语言 > 详细

Python OpenCV —— Arithmetic

时间:2016-09-29 07:43:17      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

   图案的算术操作。

# -*- 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

标签:

原文地址:http://www.cnblogs.com/buzhizhitong/p/5918494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!