So as you scanned across there points you would 1st check these distance on these points?
2nd scan would compute these points
And … for the whole line.
Then you would look at the next 2nd line and check these distances.
I am not sure if you would check the diagonals.
so…
I would build an array of objects from the center points.
center = new cv.Point(m10 / m00, m01 / m00);
That could look something like this
centers = [
{x: 492.88631548396455, y: 735.8633289798287},
{x: 305.8166012501817, y: 735.8900421572902},
{x: 586.8836980920314, y: 735.4609427609428},
{x: 399.00210119347787, y: 735.5012607160868},
{x: 492.87410947002604, y: 640.5096437880104},
{x: 305.82291485286436, y: 640.5259446282431},
{x: 399.03044293348995, y: 639.6068720445451},
{x: 211.99113832047408, y: 639.5925304707592},
{x: 586.0671880255634, y: 545.1754681018051},
{x: 492.87634736628024, y: 545.2052935878439},
{x: 305.839043571284, y: 545.2109173967096},
{x: 211.97433955914522, y: 544.4378260137977},
{x: 586.4577587711642, y: 449.80976901146215}
]
You can access this array like a 2D array like this
You need to loop of the centers and using the above formula look at the values of the point above, below, left and right and check their distance and saving the result to the centers array so that each entry looks like this.
{x: 492.88631548396455, y: 735.8633289798287,
[
{top: [center_idx,distanceX,distanceY],
bottom:[center_idx,distanceX,distanceY],
left:[center_idx,distanceX,distanceY],
right:[center_idx,distanceX,distanceY]},
top: [center_idx,distanceX,distanceY],
bottom:[center_idx,distanceX,distanceY],
left:[center_idx,distanceX,distanceY],
right:[center_idx,distanceX,distanceY]},
top: [center_idx,distanceX,distanceY],
bottom:[center_idx,distanceX,distanceY],
left:[center_idx,distanceX,distanceY],
right:[center_idx,distanceX,distanceY]},
top: [center_idx,distanceX,distanceY],
bottom:[center_idx,distanceX,distanceY],
left:[center_idx,distanceX,distanceY],
right:[center_idx,distanceX,distanceY]},
]},
center_idx is the index number into the centers array. This is useful as you can use the data to populate that point too because the two points have the same data. (distance from a point to b point equals b point to a point)
This should help you get started.
There could be other ways to do this. The circle.jpg in your example is very uniform as it’s on a grid.
Also you need to delete the objects you make in opencv as it needs to free up the memory used.
// clean memory
src.delete();
dst_gray.delete();
dst_binary.delete();
label.delete();
stats.delete();
centroids.delete();
hierarchy.delete();
contours.delete();