I see several possible measures for addition:
Try an approximate line with an approximate window, and then check how many segments of the approximate line, fewer segments are the best line. (This can lead to problems in most left-handed cases when a row contains several segments)
,
.