title: How to detect Sudoku grid board in OpenCV
body: <p>I'm working on a personal project using <code>opencv</code> in python. Want to detect a sudoku grid. </p>
  
  <p>The original image is:</p>
  
  <p><a href="https://i.stack.imgur.com/hsLhe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hsLhe.jpg" alt="enter image description here"></a></p>
  
  <p>So far I have created this:</p>
  
  <p><a href="https://i.stack.imgur.com/CZ8KI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CZ8KI.jpg" alt="enter image description here"></a></p>
  
  <p>Then tried to select a big blob. Result may be similar to this:</p>
  
  <p><a href="https://i.stack.imgur.com/TjMKO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TjMKO.jpg" alt="enter image description here"></a></p>
  
  <p>I got a black image as result:</p>
  
  <p><a href="https://i.stack.imgur.com/U1xpa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U1xpa.jpg" alt="enter image description here"></a></p>
  
  <p>The code is: </p>
  
  <pre class="lang-py prettyprint-override"><code>import cv2
  import numpy as np
  
  def find_biggest_blob(outerBox):
     max = -1
     maxPt = (0, 0)
  
     h, w = outerBox.shape[:2]
     mask = np.zeros((h + 2, w + 2), np.uint8)
  
     for y in range(0, h):
       for x in range(0, w):
  
         if outerBox[y, x] &gt;= 128:
  
           area = cv2.floodFill(outerBox, mask, (x, y), (0, 0, 64))
  
  
     #cv2.floodFill(outerBox, mask, maxPt, (255, 255, 255))
  
     image_path = 'Images/Results/sudoku-find-biggest-blob.jpg'
  
     cv2.imwrite(image_path, outerBox)
  
     cv2.imshow(image_path, outerBox)
  
  
   def main():
     image = cv2.imread('Images/Test/sudoku-grid-detection.jpg', 0)
  
     find_biggest_blob(image)
  
     cv2.waitKey(0)
  
     cv2.destroyAllWindows() 
  
  
  if __name__ == '__main__':
     main()
  </code></pre>
  
  <p>The code in repl is: <a href="https://repl.it/@gmunumel/SudokuSolver" rel="nofollow noreferrer">https://repl.it/@gmunumel/SudokuSolver</a></p>
  
  <p>Any idea?</p>