find intersection point of two lines drawn using houghlines opencv

前端 未结 5 1234
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 08:50

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         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-02 09:40

    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

提交回复
热议问题