globを使ってパスを指定しフォルダ内の画像をまとめて512*256に切り取るプログラムを書きたかったのですが,以下のようなエラーが出てしまい困っています.おそらくfor文がよくないのかなとは思っているのですが...
エラー内容
File "c:\Users\Document\pic_operate\cut.py", line 1, in <module>
from PIL import Image
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 44, in
<module>
import defusedxml.ElementTree as ElementTree
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\defusedxml\ElementTree.py", line 12, in <module>
from xml.etree.ElementTree import ParseError
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\xml\etree\ElementTree.py", line 2085, in
<module>
from _elementtree import *
AttributeError: module 'copy' has no attribute 'deepcopy'
cut.py
1from PIL import Image 2import glob 3 4def crop_center(pil_img, crop_width, crop_height): 5 img_width, img_height = pil_img.size 6 return pil_img.crop(((img_width - crop_width) // 2, 7 (img_height - crop_height) // 2, 8 (img_width + crop_width) // 2, 9 (img_height + crop_height) // 2)) 10 11glob.glob("C:/Users/Documents/datasets/one/train_A/*.png") 12 13for pic_num in (file): 14 15 im_new = crop_center(pic_num,512,256) 16 im_new.save("C:/Users/Documents/datasets/one/train_A/%d.png" %im_new) 17
回答1件
あなたの回答
tips
プレビュー