반응형
PIL을 사용하여 사진을 여러 조각으로 분할하려고합니다.
def crop(Path,input,height,width,i,k,x,y,page):
im = Image.open(input)
imgwidth = im.size[0]
imgheight = im.size[1]
for i in range(0,imgheight-height/2,height-2):
print i
for j in range(0,imgwidth-width/2,width-2):
print j
box = (j, i, j+width, i+height)
a = im.crop(box)
a.save(os.path.join(Path,"PNG","%s" % page,"IMG-%s.png" % k))
k +=1
하지만 작동하지 않는 것 같습니다. 사진을 분할하지만 정확한 방식은 아닙니다 (해 볼 수 있음).
해결 방법
from PIL import Image
def crop(path, input, height, width, k, page, area):
im = Image.open(input)
imgwidth, imgheight = im.size
for i in range(0,imgheight,height):
for j in range(0,imgwidth,width):
box = (j, i, j+width, i+height)
a = im.crop(box)
try:
o = a.crop(area)
o.save(os.path.join(path,"PNG","%s" % page,"IMG-%s.png" % k))
except:
pass
k +=1
참조 페이지 https://stackoverflow.com/questions/5953373
반응형
'파이썬' 카테고리의 다른 글
파이썬 Python - converting textfile contents into dictionary values/keys easily (0) | 2020.10.03 |
---|---|
파이썬 python-3.x에서 사전을 사용하여 문자열을 어떻게 포맷합니까? (0) | 2020.10.03 |
파이썬 sum ()과 같은 함수는 무엇입니까? 생성물()? (0) | 2020.10.03 |
파이썬 Python datetime을 타임 스탬프로 변환하고 UTC로 다시 변환하면 여전히 현지 시간대를 사용합니다. (0) | 2020.10.03 |
파이썬 Python의 MATLAB 스타일 find () 함수 (0) | 2020.10.03 |
댓글