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
from PIL import Image import glob def crop_center(pil_img, crop_width, crop_height): img_width, img_height = pil_img.size return pil_img.crop(((img_width - crop_width) // 2, (img_height - crop_height) // 2, (img_width + crop_width) // 2, (img_height + crop_height) // 2)) glob.glob("C:/Users/Documents/datasets/one/train_A/*.png") for pic_num in (file): im_new = crop_center(pic_num,512,256) im_new.save("C:/Users/Documents/datasets/one/train_A/%d.png" %im_new)
まだ回答がついていません
会員登録して回答してみよう