cv2.add(src1,src2,dst,…)
import cv2
d=cv2.imread('d.jpg')
e=cv2.imread('e.jpg')
result=cv2.add(d,e)
cv2.imshow('d',d)
cv2.imshow('e',e)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destoryAllWindows()
cv2.subtract(src1,src2,dst,…)
import cv2
import numpy as np
img = cv2.imread('a.jpg')
x=np.ones(img.shape,dtype='uint8')*100
#图像各像素减100
result=cv2.subtract(img,x)
cv2.imshow('original',img)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destoryAllWindows()
cv2.bitwise_and(src1,src2,dst,…)
import cv2
import numpy as np
img = cv2.imread('e.jpg')
row,col=img.shape[:2]
c=cv2.imread('d.jpg')
cv2.circle(c,(row//2,col//2),100,255,-1)
result=cv2.bitwise_and(img,c)
cv2.imshow('c',img)
cv2.imshow('circle',c)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destoryAllWindows()
cv2.bitwise_or(src1,src2,dst,…)
import cv2
import numpy as np
img = cv2.imread('e.jpg')
row,col=img.shape[:2]
c=cv2.imread('d.jpg')
cv2.circle(c,(row//2,col//2),100,255,-1)
result=cv2.bitwise_or(img,c)
cv2.imshow('c',img)
cv2.imshow('circle',c)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destoryAllWindows()
cv2.bitwise_xor(src1,src2,dst,…)
import cv2
import numpy as np
img = cv2.imread('e.jpg')
row,col=img.shape[:2]
c=cv2.imread('d.jpg')
cv2.circle(c,(row//2,col//2),100,255,-1)
result=cv2.bitwise_xor(img,c)
cv2.imshow('c',img)
cv2.imshow('circle',c)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destoryAllWindows()
cv2.bitwise_not(src1,src2,dst,…)
import cv2
import numpy as np
img = cv2.imread('e.jpg')
result=cv2.bitwise_not(img)
cv2.imshow('c',img)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destoryAllWindows()
cv2.addWeighted(src1,alpha,src2,beta,gamma)
import cv2
import numpy as np
img = cv2.imread('e.jpg')
d=cv2.imread('d.jpg')
result=cv2.addWeighted(img,0.6,d,0.5,0.5)
cv2.imshow('e',img)
cv2.imshow('d',d)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destoryAllWindows()
import cv2
import numpy as np
img=cv2.imread('e.jpg')
imgd=cv2.imread('d.jpg')
a=np.zeros((200,200,3))
#通过像素矩阵获取ROI区域
a=img[150:350,150:350]
imgd[100:300,100:300]=a
cv2.imshow('a',imgd)
cv2.waitKey(0)
cv2.destoryAllWindows()
cv2.cvtColor(src,code,dst,…)
import cv2
img=cv2.imread('d.jpg')
result1=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
result2=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
result3=cv2.cvtColor(result2,cv2.COLOR_GRAY2BGR)
cv2.imshow('img',img)
cv2.imshow('r1',result1)
cv2.imshow('r2',result2)
cv2.imshow('r3',result3)
cv2.waitKey(0)
cv2.destoryAllWindows()