在扩充数据集时,需要用到图片翻转的操作,下面是对一个数据集中的批量数据进行翻转并存储到另一个文件夹中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| import cv2 import os
def read_path(file_pathname): for filename in os.listdir(file_pathname): print(filename) img = cv2.imread(file_pathname+'/' + filename) img1 = cv2.flip(img, 1) cv2.imwrite('E:/data/MNIST/test_flip' + "/" + filename, img1)
path = "E:/data/MNIST/test" read_path(path)
|