title: How to detect the outlines of cells of a pillbox in opencv in python?
body: <p>So I am trying to make an opencv program that can detect which cells of a pillbox have pills in them.</p>
  
  <p>My initial idea was to:</p>
  
  <ul>
  <li>find all the edges using canny</li>
  <li>Run hough transform to find the borders of the cells</li>
  <li>see which of the 14 cells have white pixels greater than a certain threshold.</li>
  </ul>
  
  <p>However, in practice, I can't really seem to find good edges using canny, since the camera is a poor quality raspberry pi camera.</p>
  
  <p>Does anybody have any suggestions of how I can go about finding the outlines of the 14 cells?</p>
  
  <p><a href="https://i.stack.imgur.com/3eSPo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3eSPo.jpg" alt="pillbox"></a></p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>So I've put masking tape on the edges of the walls, and through some processing, am able to obtain images like the following</p>
  
  <p><a href="https://i.stack.imgur.com/54QRu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/54QRu.jpg" alt="enter image description here"></a></p>
  
  <p>Now, how do I get the 14 masks of the interiors of the 14 cells? I tried doing a hough transform on this image, but it's still creating spurious lines it shouldn't, and not creating lines it should</p>