import cv2
import os
import matplotlib.pylab as plt
def image_add(source_path,save_path):
if not os.path.exists(source_path):
return
if not os.path.exists(save_path):
os.makedirs(save_path)
image_save = cv2.imread(os.path.join(source_path, os.listdir(source_path)[0]))
for i in range(1,len(os.listdir(source_path))):
image_save = cv2.add(image_save,cv2.imread(os.path.join(source_path,os.listdir(source_path)[i])))
if i % 3 == 0:
cv2.imwrite(os.path.join(save_path,os.listdir(source_path)[i]),image_save)
image_save = cv2.imread(os.path.join(source_path, os.listdir(source_path)[i]))
# print(image_save)
def image_add1(img_path1,img_path2):
img1 = plt.imread(img_path1,0)
img2 = plt.imread(img_path2,0)
# img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
print(img1)
print(img2)
image_save = cv2.add(img1, img2)
cv2.imwrite('add.jpg',image_save)
if __name__ == '__main__':
image_add1('H:\\LONGBO\\SJ(data)\\SJ_test\data\\19225-right.jpg','H:\\LONGBO\\SJ(data)\\pre\\19225-right.jpg')