title: Detect missing squares in color calibration chart opencv python
body: <p>I am am currently working on a method to extract colors from a macbeth color chart. So far I have had moderate success by using thresholding and then extracting square contours. Sadly through, colors that are too close to each other either mix together or do no get detected.</p>
  
  <p>The code in it's current form:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://pastebin.com/embed_js/mNi0TcDE"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/IPF2y.png" rel="nofollow noreferrer">The image before any processing</a></p>
  
  <p>After thresholding, you can see that there are areas where lines are incomplete due to too small differences in color. I have tried to use dilation to midigate these issues and it does work to a degree. But not enough to detect all squares.</p>
  
  <p><a href="https://i.stack.imgur.com/AmVFx.png" rel="nofollow noreferrer">Image after thresholding</a> </p>
  
  <p>This results in the following contours being detected</p>
  
  <p><a href="https://i.stack.imgur.com/ccNc2.png" rel="nofollow noreferrer">Detected contours</a></p>
  
  <p>I have tried using: </p>
  
  <ol>
  <li>Hough lines, sadly no lines here detected.</li>
  <li>Centroids of contours, but I was unable to find a way to use centroids to draw lines and detect the centers of the missing contours</li>
  <li>Corner detection, corners where found. But I was unsuccessful in finding a real way to put them to use.</li>
  </ol>
  
  <p>Can anyone point me in the right direction?</p>
  
  <p>Thaks in advance,
  Emil</p>