Ask Your Question
0

Create a grid over image without template matching

asked 2018-05-15 15:45:31 -0500

AnnaR gravatar image

updated 2018-05-15 18:56:56 -0500

Hi all,

I have this image:

image description

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 flag offensive close merge delete

Comments

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

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

Eduardo gravatar imageEduardo ( 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.

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

Find contour to solve it?

hoang anh tuan gravatar imagehoang anh tuan ( 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!

AnnaR gravatar imageAnnaR ( 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.

hoang anh tuan gravatar imagehoang anh tuan ( 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

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

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-16 09:57:23 -0500

kbarni gravatar image

updated 2018-05-16 09:59:29 -0500

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-05-15 15:45:31 -0500

Seen: 117 times

Last updated: May 16