Please go line by line and tell me what each lines means.
Posted: Fri Apr 29, 2022 7:08 am
Please go line by line and tell me what each lines means.
File Edit Format Run Options Window Help 1 import cv2 2 import numpy as np 3 lines list = [] 4 # Read image 5 image = cv2.imread('pic2.png') 6 7 # Convert image to grayscale 8 gray = cv2.cvtColor (image, cv2.COLOR_BGR2GRAY) = 10 # Use canny edge detection 11 edges cv2.Canny (gray,50, 150, apertureSize=3) 12 13 # Apply HoughLinesP method to 14 # to directly obtain line end points 15 lines = cv2.HoughLines 16 edges, # Input edge image 17 1, # Distance resolution in pixels 18 np.pi/180, # Angle resolution in radians 19 threshold=100, # Min number of votes for valid line 20 minLineLength=5, # Min allowed length of line 21 maxLineGap=10 # Max allowed gap between line for joining them 22 ) 23 24 # Iterate over points 25 for points in lines: 26 # Extracted points nested in the list 27 xl, yl,x2, y2=points[0] 28 # Draw the lines joing the points 29 # On the original image 30 cv2.line (image, (x1, yl), (x2, y2), (0,255,0),2) 31 # Maintain a simples lookup list for points 32 lines_list.append([ (x1, yl), (x2,y2)]) 33 34 # Save the result image 35 cv2.imwrite('detectedLines.png', image) 36
File Edit Format Run Options Window Help 1 import cv2 2 import numpy as np 3 lines list = [] 4 # Read image 5 image = cv2.imread('pic2.png') 6 7 # Convert image to grayscale 8 gray = cv2.cvtColor (image, cv2.COLOR_BGR2GRAY) = 10 # Use canny edge detection 11 edges cv2.Canny (gray,50, 150, apertureSize=3) 12 13 # Apply HoughLinesP method to 14 # to directly obtain line end points 15 lines = cv2.HoughLines 16 edges, # Input edge image 17 1, # Distance resolution in pixels 18 np.pi/180, # Angle resolution in radians 19 threshold=100, # Min number of votes for valid line 20 minLineLength=5, # Min allowed length of line 21 maxLineGap=10 # Max allowed gap between line for joining them 22 ) 23 24 # Iterate over points 25 for points in lines: 26 # Extracted points nested in the list 27 xl, yl,x2, y2=points[0] 28 # Draw the lines joing the points 29 # On the original image 30 cv2.line (image, (x1, yl), (x2, y2), (0,255,0),2) 31 # Maintain a simples lookup list for points 32 lines_list.append([ (x1, yl), (x2,y2)]) 33 34 # Save the result image 35 cv2.imwrite('detectedLines.png', image) 36