Ask Your Question

Revision history [back]

How to detect the road in the diablo2?

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()

How to detect the road in the diablo2?

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()cv2.destroyAllWindows() ```

How to detect the road in the diablo2?

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

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.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

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

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)

3)

cv2.waitKey(0) cv2.destroyAllWindows() ```