当前位置:网站首页>【格式转换】将JPEG图片批量处理为jpg格式
【格式转换】将JPEG图片批量处理为jpg格式
2022-08-10 05:29:00 【Time.Xu】
数据图片中有JPEG和jpg两种文件格式,train时会出现报错而无法正常训练,故需要将文件格式统一成.jpg格式后便可成功训练将JPEG等格式批量转化为jpg格式。
代码如下,注意路径中不应存在中文。
import os
import cv2 as cv
image_path = 'J:/102HorizontalProject/zong/image' #设置图片读取路径
save_path = 'J:/yolov5-master-cow/data/images' #设置图片保存路径
if not os.path.exists(save_path): #判断路径是否正确,并打开
os.makedirs(save_path)
image_file = os.listdir(image_path)
for image in image_file:
if image.split('.')[-1] in ['bmp', 'jpg', 'jpeg', 'png', 'JPG', 'PNG']:
str = image.rsplit(".", 1) #从右侧判断是否有符号“.”,并对image的名称做一次分割。如112345.jpeg分割后的str为["112345","jpeg"]
output_img_name = str[0] + ".jpg" #取列表中的第一个字符串与“.jpg”放在一起。
src = cv.imread(os.path.join(image_path, image))
newimg = cv.imwrite(save_path + '/' + output_img_name, src)
print('FINISHED')
边栏推荐
- 大佬们,mysql cdc(2.2.1跟之前的版本)从savepoint起有时出现这种情况,有没有什
- EasyGBS连接mysql数据库提示“can’t connect to mysql server”,该如何解决?
- oracle cdc时,设置并行度2插槽数1,最终任务只有一个tm,是不是因为oracle不支持并发
- 聊聊 API 管理-开源版 到 SaaS 版
- 细数国产接口协作平台的六把武器!
- How to use Apifox's Smart Mock function?
- 基于Qiskit——《量子计算编程实战》读书笔记(五)
- Qiskit学习笔记(三)
- openGauss源码,在window系统用VSCode维护吗?
- 一篇文章掌握整个JVM,JVM超详细解析!!!
猜你喜欢
论文精度 —— 2017 ACM《Globally and Locally Consistent Image Completion》
基于BP神经网络的多因素房屋价格预测matlab仿真
几种绘制时间线图的方法
大咖说·对话生态|当Confluent遇见云:实时流动的数据更有价值
如何用Apifox 的智能Mock功能?
Get started with the OAuth protocol easily with a case
Buu Web
【静态代理】
EasyGBS connects to mysql database and prompts "can't connect to mysql server", how to solve it?
mysql常用命令有什么
随机推荐
[Thesis Notes] Prototypical Contrast Adaptation for Domain Adaptive Semantic Segmentation
应用在智能触摸遥控器中的触摸芯片
树莓派入门(4)LED闪烁&呼吸灯
Advanced Feature Selection Techniques in Linear Models - Based on R
pytorch 学习
【LeetCode】41. The first missing positive number
Pony语言学习(六):Struct, Type Alias, Type Expressions
基于BP神经网络的多因素房屋价格预测matlab仿真
OneFlow源码解析:算子指令在虚拟机中的执行
Interface documentation evolution illustration, some ancient interface documentation tools, you may not have used it
Transforming into a product, is it reliable to take the NPDP test?
基于Qiskit——《量子计算编程实战》读书笔记(三)
在vscode中屏蔽Alt热键
Qiskit 学习笔记2
深度梳理:防止模型过拟合的方法汇总
canvas canvas drawing clock
Zhongang Mining: Strong downstream demand for fluorite
Tkinter 入门之旅
SQLSERVER 2008 parses data in Json format
我用这一招让团队的开发效率提升了 100%!