Find sudoku grid using OpenCV and Python : <p>I'm trying to detect the grid in sudoku puzzles using OpenCV but I'm having troubles with the last steps (I guess).</p>

<p>What I'm doing is:</p>

<ul>
<li>Downsaple the image</li>
<li>Blur it</li>
<li>Applying a highpass filter (bilateral)</li>
<li>Thresholding the image, using adaptive threshold</li>
<li>Some dilations and erosions</li>
</ul>

<p>All this gives me the following images:</p>

<p><a href="https://i.stack.imgur.com/BoCzp.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/BoCzp.jpg" alt="Original image downsampled and blurred."></a></p>

<p><a href="https://i.stack.imgur.com/DfJio.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/DfJio.jpg" alt="enter image description here"></a></p>

<p>From now on, I need to detect the grid, and I found a few methods of how to do that but none of them gave me the confidence of being robust enough. </p>

<p>The first one is to find lines using Hough transform but I find a lot of spurious lines. </p>

<p><a href="https://i.stack.imgur.com/EZuOj.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/EZuOj.jpg" alt="Hough transform."></a></p>

<p>The other is using connected components, which gives me the best results. I tried to implement RANSAC as a way to get the right centroids, but I'm not having good results and also takes a while to get the answer ("a while" is less than 2 seconds, but later I want to use it in real time video).</p>

<p><a href="https://i.stack.imgur.com/q17rj.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/q17rj.jpg" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/ToPpJ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/ToPpJ.jpg" alt="enter image description here"></a></p>

<p>Any idea how this can be done? I mean, how can I discard the wrong centroids and start solving the sudoku?  </p>
