2016-07-07 2 views
0

도로의 가장자리를 찾는 데 관심이 있습니다. 출력 이미지에는 가장자리 만 표시해야합니다. 여기에 내 입력 화상 중 하나이다 :opencv를 사용하여 도로 모서리 찾기

enter image description here

그러나 출력 가장자리 역시 왜곡이나 노이즈가 많이있다. 다음은 출력입니다 : 내가 분수령 알고리즘을 적용 시도

output

하지만 제대로 도로를 감지하지 않습니다. 단지 가장자리를 표시 inoder을 어떻게해야

import cv2 
import numpy as np 

img = cv2.imread('road2.jpg',0) 

ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) 
kernel = np.ones((5,5),np.uint8) 
erosion = cv2.erode(thresh1,kernel,iterations = 1) 
#Removing noise from image 
blur = cv2.blur(img,(5,5)) 
#finding edges using edge detection 
edges = cv2.Canny(blur, 100 ,200) 


laplacian = cv2.Laplacian(edges, cv2.CV_8UC1) 
sobely = cv2.Sobel(laplacian,cv2.CV_8UC1, 0, 1, ksize=5) 
im2, contours, hierarchy = cv2.findContours(sobely,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 

frame = cv2.drawContours(im2, contours, -1, (255,0,0), 3) 
cv2.imshow('window',frame) 

cv2.waitKey(0) 
cv2.destroyAllWindows() 

:

여기 내 코드입니다. 출력 가장자리에 가장자리 만 있으면 나중에 도로의 중간 차선을 찾기 위해이 가장자리가 필요할 것입니다.

+3

이것은 쉽게 당신이 googlecar에 착석했을 것입니다 ... – Julien

+1

그러나 도로 감지는 많은 사람들이 확실히 구현할 수 있습니다. – parikshit

+0

그리고이 질문에 왜 부정 투표를해야합니까? – parikshit

답변

0

결과는 here으로 볼 수 있습니다. 완벽하지는 않지만 최선을 다할 수 있습니다. 아이디어는 here

코드는 가정이 이미지 작동에서 촬영이 :

상의 소실점에서 만나 도로에는 자동차, (왼쪽 및 오른쪽) 다음이 표시가없는 경우 삼각형을 형성합니다. 따라서 삼각형으로 근사 할 수있는 가장 큰 윤곽 만 유지합니다.

import cv2 
import numpy as np 

img = cv2.imread('road2.jpg',0) 

ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) 
kernel = np.ones((5,5),np.uint8) 
erosion = cv2.erode(thresh1,kernel,iterations = 1) 
#Removing noise from image 
blur = cv2.blur(img,(5,5)) 
#finding edges using edge detection 
edges = cv2.Canny(blur, 100 ,200) 


laplacian = cv2.Laplacian(edges, cv2.CV_8UC1) 
sobely = cv2.Sobel(laplacian,cv2.CV_8UC1, 0, 1, ksize=5) 

# Do a dilation and erosion to accentuate the triangle shape 
dilated = cv2.dilate(sobely,kernel,iterations = 1) 
erosion = cv2.erode(dilated,kernel,iterations = 1) 

im2, contours, hierarchy = cv2.findContours(erosion,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 

#keep 10 largest contours 
cnts = sorted(contours, key = cv2.contourArea, reverse = True)[:10] 
screenCnt = None 

for c in cnts: 
    # approximate the contour 
    peri = cv2.arcLength(c, True) 
    approx = cv2.approxPolyDP(c, 0.05 * peri, True) 
    # if our approximated contour has three points, then 
    # it must be the road markings 
    if len(approx) == 3: 
     screenCnt = approx 
     break 
cv2.drawContours(img, [screenCnt], -1, (0, 255, 0), 3) 
cv2.imshow("Road markings", img) 
cv2.waitKey(0) 
+0

@parikshit 이것이 도움이된다면 해결책을 받아 들여야합니다. –

관련 문제