直接在文件夹中生成(需要手动放置文件夹)(推荐)
# -*- coding: utf-8 -*-
"""
https://blog.csdn.net/qq_41413211/article/details/126813017
"""
import os
import numpy as np
import json
from glob import glob
import cv2
def change_image_format(label_path, suffix='.jpg'):
"""
统一当前文件夹下所有图像的格式,如'.jpg'
:param suffix: 图像文件后缀
:param label_path:当前文件路径
:return:
"""
externs = ['png', 'jpg', 'JPEG', 'BMP', 'bmp']
files = list()
for extern in externs:
files.extend(glob(label_path + "\\*." + extern))
for file in files:
name = ''.join(file.split('.')[:-1])
file_suffix = file.split('.')[-1]
if file_suffix != suffix.split('.')[-1]:
new_name = name + suffix
image = cv2.