KITTI3D数据集 图片检查脚本

问题

百度网盘下载的kitti数据集图片存在损坏或者丢失,为了后续处理需要对这些文件进行增减等处理。所以写了一个python脚本检查这些错误或者丢失的文件。

链接: https://pan.baidu.com/s/1l7oKQMeTDnaYa6rqZAjXpw 提取码: 8yad
–来自百度网盘超级会员v5的分享

对于截断的图片,没有找到合适的修复方法,就做了一个简单的裁剪。如果你有其他方法修复,欢迎交流

code

# -*- coding: utf-8 -*-
import io
import os
from PIL import Image
NO_png=[]
Bad_png=[]
imageSets_path='/home/zgq/Documents/dataSet/kitti/ImageSets'
path ='/home/zgq/Documents/dataSet/kitti/training'
txtfile=(os.path.join(imageSets_path,'trainval.txt'))
f= os.listdir(path+'/image_2')

def checkdataflow(file):
    try:
        with open(file,'rb') as image_file:
            image_byte=image_file.read()
        image_file=io.BytesIO(image_byte)
        image=Image.open(image_file)
        image.verify()
        image_file.close()
        image.close()
    except:
        Bad_png.append(file)
        try:
            image_file.close()
        except:
            pass
        try:
            image.close()
        except:
            pass
        # raise
    else:
        pass
        # print('Image ok, format is %s.' % image.format)


def write_result(file,result):
    with open(file,'w') as f:
        f.write(result)

listofLines=list()
with open(txtfile,'r') as file:
    for line in file:
        if line[-1]!='\n':
            line=line+'\n'
        p=os.path.join(path,'image_2/'+(line[:-1]+'.png'))
        # if p=='/home/zgq/Documents/dataSet/kitti/training/image_2/00748.png':
        #     print(p)
        if not os.path.exists(p):
            NO_png.append(p)
        else:
            checkdataflow(p)



print('absent one :')
print(NO_png)

print('Bad one :')
print(Bad_png)



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值