line2.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import cv2
  2. import numpy as np
  3. # define a video capture object
  4. vid = cv2.VideoCapture(0)
  5. while(True):
  6. # Capture the video frame
  7. # by frame
  8. ret, frame = vid.read()
  9. # Convert to grayscale.
  10. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  11. #Create default parametrization LSD
  12. lsd = cv2.createLineSegmentDetector(1000)
  13. lines = lsd.detect(gray)[0] #Position 0 of the returned tuple are the detected lines
  14. # The below for loop runs till r and theta values
  15. # are in the range of the 2d array
  16. if lines is not None:
  17. for line in lines:
  18. print (line)
  19. # Draw detected lines in the image
  20. frame = lsd.drawSegments(frame,lines)
  21. # Display the resulting frame
  22. cv2.imshow('frame', frame)
  23. # the 'q' button is set as the
  24. # quitting button you may use any
  25. # desired button of your choice
  26. if cv2.waitKey(1) & 0xFF == ord('q'):
  27. break
  28. # After the loop release the cap object
  29. vid.release()
  30. # Destroy all the windows
  31. cv2.destroyAllWindows()