我想要分割一些Bangali脚本。在分割线条的同时,我获得了第一条线的预期图像。但从第二行开始,我得到一个完整的黑色图像。这是我的裁剪代码。
def linecut(line_start,line_end,name):
print("called" , name)
#imArray = np.asarray(im)
print("Start=",line_start,"end=",line_end)
# create mask
plygn = line_start
i=len(line_end)-1
while i>=0:
plygn.append(line_end[i])
i-=1
print(plygn)
#print(imArray.shape)
region = Polygon(plygn)
for index, pixel in np.ndenumerate(pixels):
# Unpack the index.
row, col, channel = index
# We only need to look at spatial pixel data for one of the four channels.
if channel != 0:
continue
point = Point(row, col)
if not region.contains(point):
im_copy[(row, col, 0)] = 255
im_copy[(row, col, 1)] = 255
im_copy[(row, col, 2)] = 255
im_copy[(row, col, 3)] = 0
im_name = str(name)+".png"
cut_image = Image.fromarray(im_copy)
plygn.clear()
cut_image.save('F:\\relax' +im_name)
cut_image.__del__()][1]
图片:https://drive.google.com/drive/folders/1kiHXPS9wA2rvUAygeuvI3Q7Wq0njkjuL