查找文件夹所有png图像,将图像中含有(255, 255, 255)像素点的图像保存到其他目录
import os
import cv2
path = r"source path"
save_path = r"save path"
if not os.path.exists(save_path):
os.mkdir(save_path)
for file in os.listdir(path):
if file.endswith(".png"):
image = cv2.imread(os.path.join(path, file))
# print(image.shape[0])
flag = False
for i in range(image.shape[0]):
for j in range(image.shape[1]):
if all(image[i][j] == [255, 255, 255]):
flag = True # 这里有点像C,image[...,i]也可以
break
break
if flag:
cv2.imwrite(os.path.join(save_path, file), image)