Advertisement
BlackDT

Untitled

Apr 14th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import cv2
  2. import numpy
  3. from math import sqrt
  4.  
  5. image_colour = cv2.imread('/Users/dariabusi/Desktop/6_1.png',cv2.IMREAD_COLOR)
  6. image = cv2.imread('/Users/dariabusi/Desktop/6_1.png',cv2.IMREAD_GRAYSCALE)
  7. invert_image = 255 - image
  8. cv2.imshow ('Experiment', invert_image)
  9. """функция поиска отрезков преобразованием Хафа (Прогрессивное вероятностное
  10. преобразование Хафа), где:
  11. по полярным координатам rho - расстояние от начала координат до прямой
  12.                        theta - угол между нормалью прямой и осью
  13. """
  14. linesP = cv2.HoughLinesP(invert_image, rho = 1, theta = numpy.pi/580, threshold = 255, minimalLength = 10, maxLineGap = 125)
  15.  
  16. maxLength=0
  17. x1,y1,x2,y2 = [0,0,0,0]
  18. for i in range(0, len(linesP)):
  19.             l = linesP[i][0]
  20.             currentLength = sqrt((l[2]-l[0])**2 + (l[3]-l[1])**2)
  21.             if currentLength>=maxLength:
  22.                 maxLength=currentLength
  23.                 x1,y1,x2,y2 = l
  24.  
  25.  
  26. print("maximum Lenght: ", maxLength)
  27. cv2.line(image_colour, (x1, y1), (x2, y2), (0,255,0), 3, cv2.LINE_AA)
  28.  
  29. cv2.imshow ('Experiment1', image_colour)
  30.  
  31.  
  32.  
  33. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement