find intersection point of two lines drawn using houghlines opencv

前端 未结 5 1240
佛祖请我去吃肉
佛祖请我去吃肉 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:35

    First of all, you need to refine the output of Hough transform (I usually do this by k-means clustering based on some criteria, e.g. slope and/or centroids of segments). In your problem, for instance, it seems like the slope for all the lines is usually in the vicinity of 0, 180, 90 degrees so you can do clustering on this basis.

    Next, there are two different ways you can get the intersecting points(which are technically the same):

    1. The equations in Bhupen's answer.
    2. Using a geometry library like Shapely or SymPy. The benefit of doing this with a geometry library is that you have access to a variety of tools you might need later on in development(intersection, interpolation, convex hull, etc. etc.)

    P.S. Shapely is a wrapper around a powerful C++ geometry library but SymPy is pure Python. You may want to consider this in case your application is time critical.

提交回复
热议问题