from glob import glob
import numpy as np
import cv2
import os
select_num = 10
a = 'bmx-all'
if not os.path.exists('./images/reselect-%s' % a):
os.makedirs('./images/reselect-%s' % a)
path = glob('./datasets/DIV/%s/*' % a)
batch_images = np.random.choice(path, size=select_num)
i = 0
for img_path in batch_images:
img = cv2.imread(img_path)
cv2.imwrite('./images/reselect-%s/%s' % (a, i) + '.png', img)
i += 1
随机选取目录下若干个文件
最新推荐文章于 2023-04-04 10:12:13 发布