From aec5690d7ef17a3bf644b88bcf4b60641de79e3b Mon Sep 17 00:00:00 2001 From: Hang Date: Wed, 6 Jan 2016 22:50:13 -0500 Subject: [PATCH] correct the pixel ordering so that lanes are on the right side of the ordering --- .../include/line_detector/LineDetector.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/catkin_ws/src/line_detector/include/line_detector/LineDetector.py b/catkin_ws/src/line_detector/include/line_detector/LineDetector.py index 8603095bd1..f52937e5e5 100644 --- a/catkin_ws/src/line_detector/include/line_detector/LineDetector.py +++ b/catkin_ws/src/line_detector/include/line_detector/LineDetector.py @@ -59,6 +59,13 @@ def __checkBounds(self, val, bound): val = bound-1 return val + def __correctPixelOrdering(self, lines, normals): + for i in range(len(lines)): + x1,y1,x2,y2 = lines[i, :] + dx, dy = normals[i, :] + if (x2-x1)*dy-(y2-y1)*dx<0: + lines[i, :] = [x2,y2,x1,y1] + def __findNormal(self, bw, lines): normals = [] if len(lines)>0: @@ -78,7 +85,9 @@ def __findNormal(self, bw, lines): if bw[y3,x3]>0 and bw[y4,x4]==0: normals[cnt,:] = [dx, dy] else: - normals[cnt,:] = [-dx, -dy] + normals[cnt,:] = [-dx, -dy] + + self.__correctPixelOrdering(lines, normals) return normals def detectLines(self, bgr, color):