| 34 | if cur==s:break |
| 35 | |
| 36 | def cut(img, lines): |
| 37 | if len(lines)<2:return |
| 38 | lines = np.array(lines).round() |
| 39 | ox,oy = lines[0] |
| 40 | for i in lines[1:]: |
| 41 | cx, cy = i |
| 42 | dx, dy = cx-ox, cy-oy |
| 43 | n = max(abs(dx), abs(dy)) + 1 |
| 44 | xs = np.linspace(cx, ox, n).round().astype(np.int16) |
| 45 | ys = np.linspace(cy, oy, n).round().astype(np.int16) |
| 46 | for x,y in zip(xs, ys): |
| 47 | for dxy in [(1,0),(0,1)]: |
| 48 | xx = x + dxy[0] |
| 49 | yy = y + dxy[1] |
| 50 | if xx<0 or xx>img.shape[1]: continue |
| 51 | if yy<0 or yy>img.shape[0]: continue |
| 52 | if img[yy,xx] == 0: continue |
| 53 | floodfill(img, xx, yy) |
| 54 | ox, oy = i |
| 55 | |
| 56 | class Mark(): |
| 57 | def __init__(self, line): |