程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Resolution screening for python data cleaning, using PIL

編輯:Python

Can you guys help me take a look?What's the problem
The code I wrote below
#Import os module
import os
#Import image package
import shutil
from PIL import Image

path = "D:\python\gaizi"
save = "D:/python/abc_666"
file_list = os.listdir(path)

for file in file_list:
imgPath = os.path.join(path, file)
img = Image.open(imgPath)
imgSize = img.size
print(imgSize, imgPath)
minSize = min(imgSize)
if minSize >= 320:
images_min = os.path.join(save, file) + ".jpg"
shutil.copy(imgPath, images_min)
img.close()
print(minSize)

if name == "main":
if not os.path.exists(save):
os.makedirs(save)
print(file)

The last error is:
C:\ProgramData\Anaconda3\python.exe D:/code/Test/test1/imgsize.py
Traceback (most recent call last):
File "D:/code/Test/test1/imgsize.py", line 13, in
img = Image.open("imgPath")
File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py", line 3092, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'imgPath'


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved