欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用Python實現(xiàn)篩選文件腳本的方法

 更新時間:2018年10月27日 10:18:30   作者:林下的碼路  
今天小編就為大家分享一篇用Python實現(xiàn)篩選文件腳本的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

在做項目時遇到需要標記數(shù)據(jù)集里面的若干圖片數(shù)據(jù),作為程序員,為避免手動一張一張的篩選,所以寫了這個Python腳本實現(xiàn)。

Python腳本如下:

# from PIL import Image
import csv
import os
import shutil
 
filename = 'img.txt'
 
def readImageName():
 with open(filename) as f:
  lines = f.readlines()
  imgnames = []
  for line in lines:
   imgnames.append(line.strip().strip(".jpg")[-4:])
  print(imgnames)
  return imgnames
 
def pickImg():
 pickImageNames = readImageName()
 # 遍歷所有圖片集的文件名
 for image in os.listdir(r"C:\Users\Administrator.PC-201708272051\Desktop\項目組\text_detect_label_data\China_SameBrowser"):
  # print(image[:-4])
  if image[:-4] in pickImageNames:
   # pickImage = Image.open((r"C:\Users\Administrator.PC-201708272051\Desktop\項目組\text_detect_label_data\China_SameBrowser/%s") % image)
   # pickImage.save((r"C:/Users/Administrator.PC-201708272051/Desktop/labeldata/%s") % image)
 
   oldname= r"C:\Users\Administrator.PC-201708272051\Desktop\項目組\text_detect_label_data\China_SameBrowser/" + image
   newname= r"C:/Users/Administrator.PC-201708272051/Desktop/labeldata/" + image
   shutil.copyfile(oldname,newname)
 
# readImageName()
pickImg()
 

以上這篇用Python實現(xiàn)篩選文件腳本的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論