Git:https://github.com/linyi0604/computer-vision
1 #Coding:utf82 3 ImportCv24 ImportNumPy as NP5 6 7 #Read in Image8img = Cv2.imread (".. /data/line1.png")9 #Convert to Grayscale imageTenGray =Cv2.cvtcolor (IMG, Cv2. Color_bgr2gray) One #Canny edge detection Aedges = Cv2. Canny (Gray, 50, 100) - """ - Canny edge detection: the There are five steps: - 1 Gaussian filter noise reduction - 2 Calculating Gradients - 3 Using non-maximum suppressed NMS on edge + 4 using a double threshold on the edge to remove false positives - 5 Analysis of all edge connections eliminates marginal edges + """ A atMinlinelength = 20 -Maxlinegap = 5 -Lines = Cv2. Houghlinesp (edges, 1, np.pi/180, 100, Minlinelength, Maxlinegap) - """ - Cv2. Houghlinesp - function: Standard Hough line transform to find all lines in an image in Parameters: - 12 Value Graph to 2 radius Accuracy + 3 Angular accuracy - 4 Shortest detection length the 5 maximum allowable notch * return: $ a list, each item is a four-tuple, which is the coordinates of the two endpoints of a line, respectivelyPanax Notoginseng """ - forLineinchlines: the forx1, y1, x2, y2inchLine : + #draw a line on the picture ACv2.line (IMG, (x1, y1), (x2, y2), (0, 255, 0), 2) the +Cv2.imshow ("edges", edges) -Cv2.imshow ("Lines", IMG) $ Cv2.waitkey () $Cv2.destroyallwindows ()
Python Opencv3 Line detection