Skip to content

Commit

Permalink
modified lanenet post process functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeShewill-CV committed Oct 24, 2018
1 parent 472788a commit 24a6a1b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lanenet_model/lanenet_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
pass

@staticmethod
def morphological_process(image, kernel_size=5):
def _morphological_process(image, kernel_size=5):
"""
:param image:
Expand All @@ -40,15 +40,15 @@ def morphological_process(image, kernel_size=5):
if len(image.shape) == 3:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

kernel = cv2.getStructuringElement(shape=cv2.MORPH_RECT, ksize=(kernel_size, kernel_size))
kernel = cv2.getStructuringElement(shape=cv2.MORPH_ELLIPSE, ksize=(kernel_size, kernel_size))

# close operation fille hole
closing = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel)
closing = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel, iterations=1)

return closing

@staticmethod
def connect_components_analysis(image):
def _connect_components_analysis(image):
"""
:param image:
Expand All @@ -61,18 +61,18 @@ def connect_components_analysis(image):

return cv2.connectedComponentsWithStats(gray_image, connectivity=8, ltype=cv2.CV_32S)

def postprocess(self, image, minarea_threshold=200):
def postprocess(self, image, minarea_threshold=15):
"""
:param image:
:param minarea_threshold: 连通域分析阈值
:return:
"""
# 首先进行图像形态学运算
morphological_ret = self.morphological_process(image, kernel_size=5)
morphological_ret = self._morphological_process(image, kernel_size=5)

# 进行连通域分析
connect_components_analysis_ret = self.connect_components_analysis(image=morphological_ret)
connect_components_analysis_ret = self._connect_components_analysis(image=morphological_ret)

# 排序连通域并删除过小的连通域
labels = connect_components_analysis_ret[1]
Expand All @@ -89,7 +89,7 @@ def postprocess(self, image, minarea_threshold=200):
if __name__ == '__main__':
processor = LaneNetPoseProcessor()

image = cv2.imread('binary_ret.png', cv2.IMREAD_GRAYSCALE)
image = cv2.imread('test.png', cv2.IMREAD_GRAYSCALE)

postprocess_ret = processor.postprocess(image)

Expand Down

0 comments on commit 24a6a1b

Please sign in to comment.