Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. #прогрессивное преобразование Хафа
  4. img = cv2.imread('/home/leti/documents/lab/laba6/6_1.png',cv2.IMREAD_REDUCED_COLOR_2)
  5. gray =255-cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  6. edges = cv2.Canny(gray,50,150,apertureSize = 3)
  7. minLineLength =30
  8. maxLineGap =1
  9. cv2.imshow('5.jpg',gray)
  10. # вариант1
  11. lenght=7
  12. i=5
  13. while lenght>5:
  14. lines = cv2.HoughLinesP(gray,1,np.pi/1800,i,minLineLength,maxLineGap)
  15. i=i+20
  16. lenght=len(lines)
  17. print(len(lines))
  18. print(i)
  19. print(len(lines))
  20. for x1,y1,x2,y2 in lines[len(lines)-1]:
  21. cv2.line(img,(x1,y1),(x2,y2),(0,255,0),1 )
  22. cv2.imshow('houghlines5.jpg',img)
  23. cv2.imwrite('/home/leti/documents/lab/laba6/houghlines5.jpg',img)
  24. cv2.waitKey(0)
  25. cv2.destroyAllWindows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement