图像中加减乘除:
import cv2
import numpy as np
def addimg(img1,cropped):
dstadd = cv2.add(img1,cropped)
cv2.imshow('dstadd', dstadd)
def subimg(img1,cropped):
dstsub = cv2.subtract(img1,cropped)
cv2.imshow('dstsub', dstsub)
def multimg(img1,cropped):
dstmult = cv2.multiply(img1,cropped)
cv2.imshow('dstmult', dstmult)
def divimg(img1,cropped):
dstdiv = cv2.divide(img1,cropped)
cv2.imshow('dstdiv', dstdiv)
def meanimg(img1,cropped):
m1 = cv2.mean(img1)
m2 = cv2.mean(cropped)
m3,dev1 = cv2.meanStdDev(img1)
m4, dev2 = cv2.meanStdDev(cropped)
print("m1:%s,m2:%s" %(m1,m2))
print("m3:%s,m3:%s,dev1: %s,dev2:%s" % (m3, m4,dev1,dev2))
img1 = cv2.imread('5.jpg',1)
img2 = cv2.imread("12.jpg",1)
cropped = img2[0:528, 0:400]
cv2.imshow('img1', img1)
cv2.imshow('cropped', cropped)
addimg(img1,cropped)
divimg(img1,cropped)
multimg(img1,cropped)
subimg(img1,cropped)
meanimg(img1,cropped)
cv2.waitKey(0)
cv2.destroyAllWindows()