3

I have an image of a road.

I applied color thresholding to it and got a mask of yellow and white markers (cv2.inRange)

Then I applied got contours of specific area on the mask to remove the noise (cv2.findContours)

I have obtained good mask which has whites as lanes and black everywhere else.

However, I cannot get the three lanes into separate arrays - I tried watershed algorithm, it gives me the boundaries of the lanes, however doesn't separate them into different arrays.

My desired result is to have three separate arrays, each containing all the pixel numbers of each lane.

I have warped the image as well.

the below screenshot is the bitwise and of mask and original warped image.

enter image description here

4

1 回答 1

1

您可以找到轮廓并填充它们并用作蒙版。要查找轮廓,您可以使用cv2.findContours()函数 in OpenCV您可以在OpenCV Docs中找到一个示例。
在文档中,您可以通过以下方式获取轮廓,

_, contours, _ = cv2.findContours(your_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

该变量contours将有一个轮廓列表。在您的情况下,每条车道都将作为单独的轮廓添加。

然后如this answer中所述,您可以创建蒙版。

masks = []
for contour in contours:
    img = np.zeros( (height, width) ) 
    cv2.fillPoly(img, pts =[contours], color=(255,255,255))
    masks.append(img)

你也可以使用 cv2.drawContours功能,设置thickness=cv2.FILLED来创建面具。

修改

首先确保所有黑色区域都(0, 0, 0)rgb值中。然后你可以在这里为函数的第二个参数尝试值,在这里函数的第三个参数尝试值findContours()

于 2018-06-20T11:38:17.100 回答