Finding circles in pictures using OpenCV

by marcel



Finding circles in pictures using OpenCV

This is a small project using OpenCV for finding the best settings of threshold parameters for the Hough Circle function.

You can simply adjust it for your needs by uploading a file and changing the parameters in

There you need to add an entry with the name of your file. To add more images just drag & drop them to the images folder.

What's the goal of this project?

It is a project which was created for research purposes on how well can circles be distinguished in a picture and how should we set values of threshold parameters for the best results using the Hough Circle function.

alt text

As it is a research project it iterates through all the values in a given range, and prints out the values which correspond to the probable quantity written in the settings. It is crucial to set a right deviation on this parameter as the results may vary siginificantly.

Easy to modify

All the settings for the example pictures can be found in and are commented for ease of modification.

Under every possible best solution can be found a histogram of radiuses of the found circles.

alt text

It could be used as an indicator of how well the parameters fit current problem.

Adding other images

It is as simple as uploading a new file to images folder for testing an image.

alt text

For the best results create a new settings entry by copying an existing one and changing the filename and values corresponding to the image.

What next?

As the function itself finds only, more or less, "perfect" circles it would be a good idea to modify it to allow ovals approximate in shape to circles as well.

It would make a possibility for counting e.g. red blood cells more accurately as it is not yet perfect. alt text


  • [2017-09-04 14:28:15] v0.1.3: Add tags to project

  • [2017-08-31 21:56:56] v0.1.2: Updated README. Added images and changed filename of the image with Neisseria.

  • [2017-08-28 11:16:28] v0.1.0: First publish.