# Create a grid over image without template matching

Hi all,

I have this image:

I was wondering if there was an efficient way of using openCV to create a grid across the image such that the centre of each grid contains a circle, and if was possible to do this without template matching. I also would like the grid to contain the half circles at the edges. I'm trying to learn openCV and could only come up with manual calculation to perform this task without pattern matching.

Any help would be appreciated! Thank you very much!

edit retag close merge delete

Circles can be detected with HoughCircles() function. See this tutorial.

To get the grid, you will have to sort the position of detected circles.

( 2018-05-15 18:08:36 -0500 )edit

Thank you for replying! I don't need to detect circles, I need a grid that would contain a circle.

( 2018-05-15 18:10:17 -0500 )edit

Find contour to solve it?

( 2018-05-15 20:47:48 -0500 )edit

I tried that already, but the bounding box sizes are sometimes different, even if they're off by just a pixel or so. Is there a way to get equal sized grids this way? I'm sorry if I'm being difficult!

( 2018-05-15 20:50:35 -0500 )edit

I think you should use findcontour. After, you add more additions such as: close contour or not, area, ... to get fit contours.

( 2018-05-15 23:07:52 -0500 )edit
1

you could project it to the image's x/y axes using reduce(), and then find an average distance between the peaks

( 2018-05-16 00:37:46 -0500 )edit

Sort by ยป oldest newest most voted

A fast, robust and elegant solution for this problem would be to use the fast fourier transform. It accurately detects the direction and frequency of the objects in the image for regular grid of circles.

If you want the precise position for each circle (if you have an irregular grid), you can use the Fourier-Mellin transform. Let's say F=FFT(Image) and G=FFT(Template).

The centers of the circles will be given by P=IFFT(F/G). If you want to get the vertices of the grid, just use the four quarter-circles as template.

more

Official site

GitHub

Wiki

Documentation