title: Measuring the diameter pictures of holes in metal parts, photographed with telecentric, monochrome camera with opencv
body: <p>Setup:</p>
  
  <ul>
  <li>Camera: Blackfly S Mono 20.0 MP</li>
  <li>Lens: Opto telecentric lens TC23080</li>
  <li>Lights: 16 green LEDS</li>
  <li>Python: 3.7.3</li>
  <li>openCV: 4.0+</li>
  </ul>
  
  <p><em>Sorry for the image links, but one image is around 20MB, also did not want to loose any quality</em></p>
  
  <p>Image samples:</p>
  
  <p><a href="https://drive.google.com/file/d/11PU-5fzvSJt1lKlmP-lQXhdsuCJPGKbN/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/11PU-5fzvSJt1lKlmP-lQXhdsuCJPGKbN/view?usp=sharing</a>
  <a href="https://drive.google.com/file/d/1B3lSFx8YvTYv3hzuuuYtphoHBuyEdc4o/view" rel="nofollow noreferrer">https://drive.google.com/file/d/1B3lSFx8YvTYv3hzuuuYtphoHBuyEdc4o/view</a></p>
  
  <p>Case:
  There will be metal parts with different shapes from 5x5 to 10x10 size(cm). Inside these metal parts there are plenty of circular holes from 2 to 10~ that have to be detected very accurately. The actual size of holes are unknown, as there are  huge variety of possible parts. The goal is to write a generic algorithm with OpenCV, that could work with any metal parts and detect circular holes.</p>
  
  <p>What we have tried:
  We have tried to detect the holes with HoughCircles algorithm with little to no success. The algorithm is either too sensitive, or it does not detect the holes at all. We have experimented with different param1 and param2 values with no success. We have also tried blurring the image and passing it through Canny before using HoughCircles, but such an approach did not produce better results. The very same algorithm works significantly better with lower resolution pictures. However, resolution cannot be sacrificed as accuracy is extremely important in this project.</p>
  
  <p><a href="https://drive.google.com/file/d/1TRdDbperi37bha0uJVALS4C2dBuaNz6u/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1TRdDbperi37bha0uJVALS4C2dBuaNz6u/view?usp=sharing</a></p>
  
  <p>The above circles were detected with the following parameters:</p>
  
  <pre><code>minradius=0
  maxradius=0
  dp=1
  param1=100
  param2=21
  </code></pre>
  
  <p>By playing around with the above parameters, we can get almost the results that we want. The problem arises when we use the same parameters with different pictures. </p>
  
  <p>The end result we want to get is the diameter of a given circle with great accuracy, and we want the same algorithm to be usable on different part pictures</p>
  
  <p>What makes this problem different from the other ones posted is that we do not know the approximate radius of a given circle (so we cannot manipulate minradius, maxradius, param1, param2 or any other values).</p>