当前位置:网站首页>【格式转换】将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')
边栏推荐
- 在vscode中屏蔽Alt热键
- Get started with the OAuth protocol easily with a case
- 我用这一招让团队的开发效率提升了 100%!
- How to get the last day of a month
- oracle rac 11g安装执行root.sh时报错
- 再肝3天,整理了90个 NumPy 例子,不能不收藏!
- 论文精读 —— 2021 CVPR《Progressive Temporal Feature Alignment Network for Video Inpainting》
- 几种绘制时间线图的方法
- How to improve product quality from the code layer
- Rpc interface stress test
猜你喜欢

pytest测试框架

暑期学前作业

Zhongang Mining: Strong downstream demand for fluorite

基于BP神经网络的多因素房屋价格预测matlab仿真

EasyGBS连接mysql数据库提示“can’t connect to mysql server”,该如何解决?

Depth of carding: prevent model fitting method

顺序表的删除,插入和查找操作

Read the excerpt notes made by dozens of lightweight target detection papers for literacy

Joomla vulnerability reproduced

8.STM32F407之HAL库——PWM笔记
随机推荐
openGauss源码,在window系统用VSCode维护吗?
论文精度 —— 2016 CVPR 《Context Encoders: Feature Learning by Inpainting》
aliases node analysis
Pony语言学习(八):引用能力(Reference Capabilities)
FPGA engineer interview questions collection 21~30
How does Jenkins play with interface automation testing?
AVL tree insertion--rotation notes
Guys, is it normal that the oracle archive log grows by 3G in 20 minutes after running cdc?
k-近邻实现手写数字识别
Guys, the test in the idea uses FlinkCDC SQL to read Mysql data and write it into Kafka. The code creates
FPGA engineer interview questions collection 41~50
基于BP神经网络的多因素房屋价格预测matlab仿真
pytorch 学习
树莓派入门(4)LED闪烁&呼吸灯
FPGA engineer interview questions collection 1~10
WSTP初体验
常用工具系列 - 常用正则表达式
通过一个案例轻松入门OAuth协议
Talk about API Management - Open Source Edition to SaaS Edition
一篇文章带你搞懂什么是幂等性问题?如何解决幂等性问题?