兩幅圖片的操作條件:兩幅圖片的長和寬必須是一樣大
1、兩幅圖片的加減乘除

1 import cv2 2 3 def twopicOperation(): 4 src1 = cv2.imread(path1) 5 src2 = cv2.imread(path2) 6 #加 7 addDst = cv2.add(src1,src2) 8 #減 9 subDst = cv2.subtract(src1,src2) 10 #乘 11 mulDst = cv2.multiply(src1, src2) 12 #除 13 divDst = cv2.divide(src1, src2)
2、圖片的與或非操作

1 def notOrAndXor(): 2 src1 = cv2.imread(path) 3 notsrc = cv2.bitwise_not(src1) 4 cv2.imshow("notsrc", notsrc) 5 am = np.ones(src1.shape,np.uint8)*100 6 orsrc = cv2.bitwise_or(src1,am) 7 cv2.imshow("orsrc",orsrc) 8 andsrc = cv2.bitwise_and(src1, am) 9 cv2.imshow("andsrc", andsrc) 10 xorsrc = cv2.bitwise_xor(src1, am) 11 cv2.imshow("xorsrc", xorsrc) 12 cv2.waitKey(0)