Advanced OpenCV 3 python hole detection


centersOpenCV is a well known computer vision library used as base framework used by major companies like Google, IBM, Sony and numerous others. It enables quick vision based tool development and results can be seen in a minutes after starting to code. This time I will show how to find round blobs (for example fiducial marks or holes on PCB). There are many ways to accomplish this task, but many of them don’t produce stable results. After many hours of research I stumbled on SimpleBlobDetector.

For this experiment I will be using standard Python 2.7 installation and OpenCV 3.1 library. OpenCV can be installed numerous ways, for Windows feel free to install from official OpenCV page (requires more steps to get started) or download from Unofficial Windows Binaries for Python Extension Packages and install with command like this:

pip install opencv_python-3.1.0-cp27-cp27m-win32.whl

Detection results

Script is provided below and hosted on Github. To start experimenting supply video file and adjust parameters if needed. Code is pretty simple and requires no more explanation (hopefully).

Comments ( 8 )

  1. varun Risbud
    niceee. where is the sample video?
    • saulius
      Thought it would be enough to have animated GIF.
  2. Sergio
    Hello first of all thank you for sharing the code. When i run it appear this error: Traceback (most recent call last): File "C:\Python27\", line 8, in detector = cv2.SimpleBlobDetector_create() AttributeError: 'module' object has no attribute 'SimpleBlobDetector_create' What can go wrong? Regards
    • saulius
      Hi Sergio, please check python and opencv versions
  3. Sergio
    I fixed it. You were right, must be some difference between my version and yours. Likely, I found the same instruction in other post and it worked for me: cv2.SimpleBlobDetector() without "_create" Im a beginner but hopefully i could help somebody. Again, thank you so much for sharing Saulius
    • saulius
      Glad to hear, Sergio!
  4. vin
    Hi Saulius, thanks for sharing, just found your helpful post, however I couldn't find your script on this page, may you kindly share the Github link? Thanks!
    • saulius
      It is strange you do not see the script. Sure check it directly on Github:

Leave a reply

Your email address will not be published.