#!/usr/bin/env python
# -*- coding:utf-8 -*-
import glob
import os
import re
import numpy as np
#用来判断图片真正的类型,并删除不是jpeg和png的
#用来判断图片的真实类型
import imghdr
# 图片目录
pic_dir = "/data2/myfile/v2/TextBoxes_plusplus/test_images/original_images"
#pic_dir = "C:\\Users\\AZERO\\Desktop\\pic\\"
for file in os.listdir(pic_dir):
print(os.path.splitext(file)[1])
if os.path.splitext(file)[1] == '.jpg':
imgType = imghdr.what(pic_dir + file)
print("imgType:" + imgType)
if (imgType != 'jpeg' and imgType !='png'):
os.remove(pic_dir + file);
os.remove(pic_dir + os.path.splitext(file)[0] + '.txt')
for file1 in os.listdir(pic_dir):
if os.path.splitext(file1)[0] == os.path.splitext(file)[0]:
print("删除失败");
print("删除成功");
网友评论