import os
import shutil
def extract_images(file_path, output_path):
# 创建输出文件夹
os.makedirs(output_path, exist_ok=True)
# 获取文件夹中所有的图片文件
images = [file for file in os.listdir(file_path) if file.endswith('.jpg')]
# 遍历图片列表,提取每隔一张图片到输出文件夹
for i in range(1, len(images), 2):
image_name = images[i]
source_path = os.path.join(file_path, image_name)
destination_path = os.path.join(output_path, image_name)
shutil.copyfile(source_path, destination_path)
print(f"已提取图片:{destination_path}")
# 调用函数并传入文件夹路径和输出文件夹路径
extract_images(r'E:\LLS\yolo\v8_ultralytics-8.1.0\mydata\rice_yolo\train - suojian\images\Tungro',
r'E:\LLS\yolo\v8_ultralytics-8.1.0\mydata\rice_yolo\train - suojian\images\Tungro1')
将一个文件夹下图片每间隔一个提取出来,一秒钟就可以做到
最新推荐文章于 2024-08-16 18:55:06 发布