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