How to detect the road in the diablo2?

asked 2017-11-10 03:15:13 -0600

updated 2017-11-10 03:28:27 -0600

The pic will be like this.

First question how to paste code in the post code seems not work for me.

20171110170646

I search the web to get the contours. Use the code below but the result seems not that satisfied so how to locate the road in the pic.

20171110171231

import numpy as np
import cv2

im = cv2.imread('path.png')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
im2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

cv2.namedWindow("Contours", cv2.WINDOW_NORMAL)
cv2.imshow("Contours", im2)

cv2.drawContours(im, contours, -1, (0,255,0), 3)
cv2.drawContours(im, contours, 3, (0,255,0), 3)
cnt = contours[4]
cv2.drawContours(im, [cnt], 0, (0,255,0), 3)


cv2.waitKey(0)
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

You should use the HSV colorspace to threshold the color of the road.

Eduardo gravatar imageEduardo ( 2017-11-10 07:18:27 -0600 )edit