有時候對于網路識別,將原始圖片放進網路中并不能達到自己想要的效果,但是有時候如果將圖片放大之后,識別率卻能夠達到意想不到的結果,現在提供一種將檔案中的圖片進行批處理放大的代碼:
import os
?
from PIL import Image
import sys
#獲取path目錄下的所有檔案
def get_imlist(path):
return[os.path.join(path,f)
for f in os.listdir(path)]
def change_size(path):
directorys=get_imlist(path)
for directory in directorys:
#不是圖片檔案就跳過
print(directory)
if not(directory.endswith('.jpg') or directory.endswith('.png') or directory.endswith('.bmp')): ##b
pass
else:
img=Image.open(directory)
s="/"
#獲取檔案名(含后綴)
oimage_name=directory[directory.rfind(s)+1:]
(oimage_width,oimage_height)=img.size
new_width=oimage_width * 3
new_height=oimage_height * 3
out=img.resize((new_width,new_height),Image.ANTIALIAS)
out.save("%s" %oimage_name) #直接替換
if __name__ == '__main__':
change_size("F:\桌面\\test")

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/375898.html
標籤:python
上一篇:【硬核】秒殺活動技術方案,Redis申請32個G,被技術總監挑戰了...
下一篇:Python KPM演算法
