_takumi

hough

Feb 18th, 2022 (edited)
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3.  
  4. img = cv2.imread("assets/frame5.jpg", 1)
  5. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  6. edges = cv2.Canny(gray, 75, 150)
  7. lines = cv2.HoughLinesP(edges, 1, np.pi/180, 50, maxLineGap=10)
  8. for line in lines:
  9.     x1, y1, x2, y2 = line[0]
  10.     cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 3)
  11. img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
  12. cv2.imwrite("assets/frame5_scanned.jpg", img)
  13. # cv2.imshow("Edges", edges)
  14. cv2.waitKey(0)
  15. cv2.destroyAllWindows()
  16.  
  17. # cap = cv.VideoCapture('assets/IMG_3477.mp4')
  18. #
  19. # while cap.isOpened():
  20. #     ret, frame = cap.read()
  21. #     if ret == True:
  22. #         cv.imshow('frame', frame)
  23. #         if cv.waitKey(1) & 0xFF == ord('q'):
  24. #             break
  25. #
  26. # cap.release()
  27. # cv.destroyAllWindows()
Add Comment
Please, Sign In to add comment