python图像差值循环
有没有大佬帮忙看一下这个程序怎么循环啊,把一整个文件夹的图片全部这样处理import cv2
img1 = cv2.imread('test1.jpg')
# 以BGR3通道读取
img2 = cv2.imread('test2.jpg')
img3 = cv2.imread('test3.jpg')
c1 = img2 - img1
# 图像差值计算
cv2.imwrite('c1.jpg', c1)
# 保存差值图像
print(c1)
# 打印结果值
c2 = img3 - img2
cv2.imwrite('c2.jpg', c2)
print(c2) 代码和案例我放附件了,你看看吧。import cv2
import os
def main():
files = os.listdir('path')
result = []
for n, v in enumerate(files[:-1]):
img1 = cv2.imread(v)
img2 = cv2.imread(files)
diff = img2 - img1
result.append(diff)
for n, v in enumerate(result):
print(f'图片{n+2} - {n+1} 结果:{v}')
if __name__ == '__main__':
main()
suchocolate 发表于 2020-12-16 10:40
代码和案例我放附件了,你看看吧。
好的好的,谢谢大佬
页:
[1]