首页 > 编程语言 >python opencv遍历图像数据集是否存在错误

python opencv遍历图像数据集是否存在错误

时间:2023-01-12 20:33:06浏览次数:46  
标签:__ 遍历 img python data opencv file path os

python3.9的环境,opencv3.4:

平时在准备图像数据集是,有可能其中有个别图像错误引起在深度学习训练到一半时报错,所有先检查一下数据集中的图像是否有错误图像:

import os
import cv2
import glob
import pathlib
import random
import numpy as np

from os import listdir, getcwd

from os.path import join

# 检查图片数据是否正确

# 图片路径
data_path = r'E:\\datasets\\CCPD2019-yolo'

# 写入到文件
trainfile = r'E:\\datasets\\err_list.txt'

if __name__ == '__main__':

file_list = os.listdir(data_path)

train_file = open(trainfile, 'a',encoding='utf-8-sig') #带BOM的UTF-8格式
for file_obj in glob.glob(data_path + '/*.jpg', recursive=True):
#for file_obj in file_list:
file_path = os.path.join(data_path, file_obj)
if os.path.exists(file_path):
a=1
#print(file_path)
else:
print('不存在', file_path)
continue
# img=cv2.imread(img_path)
img = cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), -1) # 解决读中文名称图片的问题
if img is None:
print('错误:%s', file_path)
d = pathlib.Path(file_path)
train_file.write(file_path + '\t' + 'carplate' + '\n')
continue

train_file.close()

标签:__,遍历,img,python,data,opencv,file,path,os
From: https://blog.51cto.com/u_8681773/6004644

相关文章

  • python opencv通过读取图像数据列表文件来检查图像数据是否存在错误
    python3.9环境,opencv3.4:平时在准备深度学习数据集时,会有图像和对应的图像列表文件,可以使用opencv通过列表文件来读取图像,看是否存在错误数据:使用python脚本来检查数据:impor......
  • 栈和寄存器虚拟机比较(以python和lua为例)
    指令长度pythonpython的指令定长,长度为16bit,其中8bit操作码,8bit操作数。///@file:Python-3.6.0\Include\code.htypedefuint16_t_Py_CODEUNIT;#ifdefWORDS_BIGEND......
  • [oeasy]python0045_四种进制_binary_octal_decimal_hexadecimal
    四种进制回忆上次内容上次研究了通过八进制数值转义\ooo把(ooo)8进制对应的ascii字符输出转义序列\n、\t是转义序列\xhh也是转义序列\ooo还......
  • [oeasy]python0045_四种进制_binary_octal_decimal_hexadecimal
    四种进制回忆上次内容上次研究了通过八进制数值转义​​\ooo​​把(​​ooo​​)<sub>​​8进制​​</sub>对应的​​ascii​​字符输出转义序列​​\n​​、​​\t​​......
  • Python----类和面向对象
    #驼峰命名法classCall_Phone():#类当中的函数叫类方法,类下面添加函数时会自动添加self.self代表类的实例#类的方法必须有一个额外的参数,惯例为self,后面......
  • python udp 接收图片并保存在本地
     疑问1.发送图片是以什么格式2.字节数据怎么保存到本地3.怎么对传输不同设备发送的图片进行分类存储4.udp实现解答1.以字节a.先用cv......
  • python 队列
    将(a,b)这样格式的数据放在队列,,get取得时候报错img=cv.imread('../xavier/UDP/qqq.jpg')img_encode=cv.imencode('.jpg',img)[1]data_encode=np.array(img_encode)dat......
  • python生成应用程序的块截方式
    代码:importos,winshellfromwin32com.clientimportDispatchpath=r"D:/workspace/wwwroot82/pyjiankong/dist/test.lnk"#Pathtobesaved(shortcut)target......
  • python requests函数处理文件上传
    问题:如何使用python的requests函数来发送一个“文件上传”的接口? 一:首先得打开文件,file={'文件参数名':open('文件路径','rb')} “文件路径”好理解,但是“......
  • python django考勤签到系统
    pythondjango考勤签到系统django考勤系统django学校考勤系统django班级考勤系统前端:htmlcss等后端:pythondjango数据库:MYSQL涉及功能:登陆、注册、退出、修改用户......