在做項目時遇到需要標記數(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)篩選文件腳本的方法-創(chuàng)新互聯(lián)
標題路徑:http://chinadenli.net/article30/dihcso.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設、商城網(wǎng)站、服務器托管、移動網(wǎng)站建設、手機網(wǎng)站建設、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容