Find intersection of two lines in polar coordinates

138 Views Asked by At

I'm using an image processing library (aForge) to process images. In this case, I'm trying to pick out a playing card from an image. aForge calculates Hough Lines, for any edges that it detects. Each Hough Line is produced in a polar coordinate from the center of the image. Here's an example, along with angle (Theta) and radius (Rad).

I want to extract the card, in order run it through an image recognition to identify suit and rank.

To extract the card, I need to calculate the intersection of the lines, then cut out the rectangular(ish) image.

Here's a sample, the Hough Lines appear in pink, the selected 1st Hough Line appears in bold.

enter image description here

3

There are 3 best solutions below

2
On BEST ANSWER

The intersection point $(x,y)$ of two Hough Lines

$$ \begin{aligned} x \cos \theta_1 + y \sin \theta_1 &= r_1 \\ x \cos \theta_2 + y \sin \theta_2 &= r_2 \\ \end{aligned}$$

is given by

$$\begin{aligned} x & = \frac{r_2 \sin \theta_1 - r_1 \sin \theta_2}{\sin(\theta_1-\theta_2)} \\ y & = \frac{r_1 \cos \theta_2 - r_2 \cos \theta_1}{\sin(\theta_1-\theta_2)} \\ \end{aligned}$$

0
On

The Hough line equation is $$ x\,\cos\theta + y\,\sin\theta = r $$ see, for example, this article.

In order to find the intersection, you have to find the solution of the following system of equations: $$ x\,\cos\theta_1 + y\,\sin\theta_1 = r_1 \\ x\,\cos\theta_2 + y\,\sin\theta_2 = r_2 $$ which can also be written as $$ \begin{pmatrix} \cos \theta_1 & \sin\theta_1 \\ \cos \theta_2 & \sin\theta_2 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} r_1 \\ r_2 \end{pmatrix} $$

1
On

Here's a sample implementing John's answer.

enter image description here