Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img = cv2.imread('lane.jpeg')
  5. gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  6. edges = cv2.Canny(gray,50,150,apertureSize = 3)
  7.  
  8. lines = cv2.HoughLines(edges,1,np.pi/180,200)
  9. for rho,theta in lines[0]:
  10. a = np.cos(theta)
  11. b = np.sin(theta)
  12. x0 = a*rho
  13. y0 = b*rho
  14. x1 = int(x0 + 1000*(-b))
  15. y1 = int(y0 + 1000*(a))
  16. x2 = int(x0 - 1000*(-b))
  17. y2 = int(y0 - 1000*(a))
  18.  
  19. cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
  20.  
  21. #cv2.imwrite('20.jpg',img)
  22. cv2.imshow('hough.jpg',img)
  23. cv2.waitKey(0)
  24. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement