Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python detect lines

img = cv2.imread('src.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)

low_threshold = 50
high_threshold = 150
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)

rho = 1  # distance resolution in pixels of the Hough grid
theta = np.pi / 180  # angular resolution in radians of the Hough grid
threshold = 15  # minimum number of votes (intersections in Hough grid cell)
min_line_length = 50  # minimum number of pixels making up a line
max_line_gap = 20  # maximum gap in pixels between connectable line segments
line_image = np.copy(img) * 0  # creating a blank to draw lines on

# Run Hough on edge detected image
# Output "lines" is an array containing endpoints of detected line segments
lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]),
                    min_line_length, max_line_gap)

for line in lines:
    for x1,y1,x2,y2 in line:
    cv2.line(line_image,(x1,y1),(x2,y2),(255,0,0),5)
    
lines_edges = cv2.addWeighted(img, 0.8, line_image, 1, 0)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas shift column down 
Python :: if string contains list of letters python 
Python :: How to draw a rectangle in cv2 
Python :: how to flatten a nested list in python 
Python :: add age categories pandas dataframe 
Python :: serial clear buffer python 
Python :: python loop through array step size 2 
Python :: reverse geocoding python 
Python :: python dict sort by value 
Python :: sample data frame in python 
Python :: python break long string multiple lines 
Python :: create a list of a certain length python 
Python :: how to redirect in django rest framework 
Python :: block window if another window is open tkinter 
Python :: Renaming an index in pandas data frame 
Python :: tkmessagebox not found 
Python :: outliers removal pandas 
Python :: how to make a minute counter in python 
Python :: int object is not subscriptable in python 
Python :: change variable type python 
Python :: change plot size matplotlib 
Python :: sum of any numbers in python 
Python :: what should you call a decimal value in python 
Python :: No package python37 available. 
Python :: pandas replace string with another string 
Python :: python copy variable 
Python :: feature scaling in python 
Python :: get a slice of string in python 
Python :: install python 3.6 on centos 
Python :: pyautogui moveTo overtime 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =