How can I get the intersection points of lines down using opencv Hough lines algorithm?
Here is my code:
import cv2
import numpy as np
import imutils
Here I have processed my image with some methods;
1.Grayscale
2.Either bitwise conversion or edge detection, it depends on the image I guess,here I have gone with bitwise conversion. First carrying out all detected line into a list.
listOflines = cv2.HoughLines(mask_inv,1,np.pi/180,200)
We will be getting values of 'rho' and 'theta', What I am doing is here creating two empty list one for vertical lines one for the horizontal lines,and appending the values of both lines in respective list.
rowsValue = []
columnValue = []
Here is the logic for vertical and horizontal lines.
for line in listOflines:
if line[0][1] == 0:
columnValue.append(line[0][0])
else:
rowsValue.append(line[0][0])
Now the important part is here, When every line passing through and intersecting one another it is intersecting that line on a particular pixel value. And we have that pixel value in terms of 'rho'.
Now lets create tuples to pass as a co-ordinate into 'cv2' function i.e. in the form of (x,y).
tupsList = [(r,c) for r in rowsValue for c in columnValue]
for tups in tupsList:
cv2.circle(image, tups, 1,(0,0,255), 2)
cv2.imshow('image',image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Thats It!! Now here the images before and after.
Original Image
Intersection Image