title: OpenCV detect grid size in Nurikabe game
body: <p>I am new to programming computer vision programs in Python and OpenCV. I need to detect size of grid in this puzzle. Every grid is square or rectangle, size from 5x5 to 27x36. I need to extract every square from this picture. This picture is from screenshot, mostly I will make photo from my mobile. Things I did so far: </p>
  
  <p>Convert to grayscale, then Gaussian Blur to remove noise from camera photo. Then I applied Adaptive Threshold. After that I found contours and warp it to rectangle. I tried Hough lines algorithm in OpenCV but it did gave me very bad results. </p>
  
  <p>What steps should I do? Thanks</p>
  
  <p><a href="http://i.imgur.com/slUj099.jpg" rel="nofollow">http://i.imgur.com/slUj099.jpg</a></p>
  
  <pre><code>gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  gaussian = cv2.GaussianBlur(gray,(3,3),0)
  thresh = cv2.adaptiveThreshold(gaussian,255,0,1,13,4)
  contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  
  area = gray.size
  for i in contours:
      if cv2.contourArea(i)&gt; area/8:
          peri = cv2.arcLength(i,True)
          approx = cv2.approxPolyDP(i,0.02*peri,True)
          cv2.drawContours(img,[approx],0,(0,255,0),2,cv2.CV_AA) 
          break 
  </code></pre>