当前位置:网站首页>【格式转换】将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')
边栏推荐
- FPGA engineer interview questions collection 11~20
- Interface documentation evolution illustration, some ancient interface documentation tools, you may not have used it
- pytorch 学习
- 8.STM32F407之HAL库——PWM笔记
- MySql's json_extract function processes json fields
- SQLSERVER 2008 parses data in Json format
- FPGA engineer interview questions collection 1~10
- Pony语言学习(六):Struct, Type Alias, Type Expressions
- Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
- Introduction to curl command
猜你喜欢

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

Interface debugging also can play this?

strongest brain (1)

An article will help you understand what is idempotency?How to solve the idempotency problem?

Matlab simulation of multi-factor house price prediction based on BP neural network

Pony语言学习(七)——表达式(Expressions)语法(单篇向)

MySQL simple tutorial

一文带你搞懂OAuth2.0

【Static proxy】

How cursors work in Pulsar
随机推荐
Interface documentation evolution illustration, some ancient interface documentation tools, you may not have used it
Guys, the test in the idea uses FlinkCDC SQL to read Mysql data and write it into Kafka. The code creates
You can‘t specify target table ‘kms_report_reportinfo‘ for update in FROM clause
看了几十篇轻量化目标检测论文扫盲做的摘抄笔记
一文带你搞懂OAuth2.0
Pulsar中游标的工作原理
Why are negative numbers in binary represented in two's complement form - binary addition and subtraction
接口调试还能这么玩?
基于Qiskit——《量子计算编程实战》读书笔记(二)
GtkD开发之路
k-近邻实现手写数字识别
Attention candidates for the soft exam! The detailed registration process for the second half of 2022 is coming!
EasyGBS connects to mysql database and prompts "can't connect to mysql server", how to solve it?
oracle rac 11g安装执行root.sh时报错
Pony语言学习(一):环境配置(续)
如何在报表控件FastReport.NET中连接XLSX 文件作为数据源?
Stacks and Queues | Valid parentheses, delete all adjacent elements in a string, reverse Polish expression evaluation, maximum sliding window, top K high frequency elements | leecode brush questions
每周推荐短视频:探索AI的应用边界
Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
细数国产接口协作平台的六把武器!
https://blog.csdn.net/vibration_xu/article/details/122580372