| 640 | |
| 641 | |
| 642 | def imshow_lanes(img, lanes, show=False, out_file=None, width=4): |
| 643 | lanes_xys = [] |
| 644 | for _, lane in enumerate(lanes): |
| 645 | xys = [] |
| 646 | for x, y in lane: |
| 647 | if x <= 0 or y <= 0: |
| 648 | continue |
| 649 | x, y = int(x), int(y) |
| 650 | xys.append((x, y)) |
| 651 | lanes_xys.append(xys) |
| 652 | lanes_xys.sort(key=lambda xys: xys[0][0] if len(xys) > 0 else 0) |
| 653 | |
| 654 | for idx, xys in enumerate(lanes_xys): |
| 655 | for i in range(1, len(xys)): |
| 656 | cv2.line(img, xys[i - 1], xys[i], COLORS[idx], thickness=width) |
| 657 | |
| 658 | if show: |
| 659 | cv2.imshow('view', img) |
| 660 | cv2.waitKey(0) |
| 661 | |
| 662 | if out_file: |
| 663 | if not os.path.exists(os.path.dirname(out_file)): |
| 664 | os.makedirs(os.path.dirname(out_file)) |
| 665 | cv2.imwrite(out_file, img) |