(_=None)
| 55 | cur_func_name = dist_func_names.next() |
| 56 | |
| 57 | def update(_=None): |
| 58 | noise = cv2.getTrackbarPos('noise', 'fit line') |
| 59 | n = cv2.getTrackbarPos('point n', 'fit line') |
| 60 | r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0 |
| 61 | outn = int(n*r) |
| 62 | |
| 63 | p0, p1 = (90, 80), (w-90, h-80) |
| 64 | img = np.zeros((h, w, 3), np.uint8) |
| 65 | cv2.line(img, toint(p0), toint(p1), (0, 255, 0)) |
| 66 | |
| 67 | if n > 0: |
| 68 | line_points = sample_line(p0, p1, n-outn, noise) |
| 69 | outliers = np.random.rand(outn, 2) * (w, h) |
| 70 | points = np.vstack([line_points, outliers]) |
| 71 | for p in line_points: |
| 72 | cv2.circle(img, toint(p), 2, (255, 255, 255), -1) |
| 73 | for p in outliers: |
| 74 | cv2.circle(img, toint(p), 2, (64, 64, 255), -1) |
| 75 | func = getattr(cv2, cur_func_name) |
| 76 | vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01) |
| 77 | cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255)) |
| 78 | |
| 79 | draw_str(img, (20, 20), cur_func_name) |
| 80 | cv2.imshow('fit line', img) |
| 81 | |
| 82 | if __name__ == '__main__': |
| 83 | print(__doc__) |
no test coverage detected