def vertical(img, threashold, outDir): ''' :param img: :param threashold: 阀值 :param outDir: 保存位置 :return: ''' w, h = img.size pixdata = img.load() x_array = [] startX = 0 endX = 0 for x in range(w): b_count = 0 for y in range(h): if pixdata[x, y] <= threashold: b_count += 1 if b_count > 0: if startX == 0: startX = x elif b_count == 0: if startX != 0: endX = x x_array.append({'startX':startX, 'endX':endX}) startX = 0 endX = 0 for i, item in enumerate(x_array): box = (item['startX'], 0, item['endX'], h) img.crop(box).save(outDir + str(i) + ".png")3807
28
5月
python 垂直投影分割
