# find a square of points?

More point-finding related questions...

If I have an image with three squares of points in it, each with four corner points and other, interior points...

What is the best way to identify each as a separate square so I can process it individually as a ROI?

They may be tilted, so the sides in 2d might not look equal, but each will have the same number of points, and each can be contained in a 4-sided polygon.

Thanks!

edit retag close merge delete

Sort by ยป oldest newest most voted

you can do the following

1. find all Regions in the image by using findcontour
2. find center for every region, you can use moments , the center point will represent the region
3. Pass the centers to Kmeans Kmean
clustring
or this link Kmean will find the clusters group of points

4. For every cluster You can use one of the following function todetect the rectangle(boundingRect, approxPolyDP,rotatedRect)

more

Thanks! I have the contours, the moments and the centroids of each point.

Stuck on kmeans... I just pass it a vector containing (x,y) of each point?

This is what I have:

findContours(threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Get the moments
vector<Moments> mu(contours.size());
for (int i = 0; i < contours.size(); i++)
{
mu[i] = moments(contours[i], false);
}

///  Get the mass centers:
vector<Point2f> centroids(contours.size());
for (int i = 0; i < contours.size(); i++)
{
centroids[i] = Point2f(mu[i].m10 / mu[i].m00, mu[i].m01 / mu[i].m00);
}


So the points are all in the centroids vector.

( 2015-04-09 07:03:13 -0600 )edit

found it here:

thanks again!

( 2015-04-09 07:59:02 -0600 )edit

you can use boundingRect function the first parameter of this function is the list of points in the squar

Example:
vector<Point> contour;
contour.push_back(Point2f(0, 0));
contour.push_back(Point2f(10, 0));
contour.push_back(Point2f(10, 10));
contour.push_back(Point2f(5, 4));
Rect ResultedboundingRect  = boundingRect(contour);

more

That gives me a bounding box for each contour though, right? What i need is to loop through a list of points, get the nearby points, and find out if a four-sided polygon can be made from them.

Picture the '5' side of a dice. Say three images of that in various places in an image. I need to identify each as a separate ROI.

thanks!

( 2015-04-09 04:04:30 -0600 )edit

Sorry i should have been more specific...

The points are the centroids of a findContours operation. I don't know which is which, they are all in the same vector.

I need a function that will tell me which points in the vector can make up a square.

( 2015-04-09 04:26:26 -0600 )edit

i did not get exactly what you need , would you add some images which describe the problem and the expected result

( 2015-04-09 04:31:45 -0600 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2015-04-09 03:18:33 -0600

Seen: 1,387 times

Last updated: Apr 09 '15