OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 09 Apr 2015 07:59:02 -0500find a square of points?http://answers.opencv.org/question/59383/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! Thu, 09 Apr 2015 03:18:33 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/Answer by essamzaky for <p>More point-finding related questions...</p>
<p>If I have an image with three squares of points in it, each with four corner points and other, interior points...</p>
<p>What is the best way to identify each as a separate square so I can process it individually as a ROI?</p>
<p>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.</p>
<p>Thanks! </p>
http://answers.opencv.org/question/59383/find-a-square-of-points/?answer=59389#post-id-59389 you can use [boundingRect](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html) 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);
Thu, 09 Apr 2015 03:52:06 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/?answer=59389#post-id-59389Comment by essamzaky for <p>you can use <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html">boundingRect</a> function
the first parameter of this function is the list of points in the squar</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59393#post-id-59393i did not get exactly what you need , would you add some images which describe the problem and the expected resultThu, 09 Apr 2015 04:31:45 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59393#post-id-59393Comment by antithing for <p>you can use <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html">boundingRect</a> function
the first parameter of this function is the list of points in the squar</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59392#post-id-59392Sorry 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.Thu, 09 Apr 2015 04:26:26 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59392#post-id-59392Comment by antithing for <p>you can use <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html">boundingRect</a> function
the first parameter of this function is the list of points in the squar</p>
<pre><code>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);
</code></pre>
http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59390#post-id-59390That 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!Thu, 09 Apr 2015 04:04:30 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59390#post-id-59390Answer by essamzaky for <p>More point-finding related questions...</p>
<p>If I have an image with three squares of points in it, each with four corner points and other, interior points...</p>
<p>What is the best way to identify each as a separate square so I can process it individually as a ROI?</p>
<p>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.</p>
<p>Thanks! </p>
http://answers.opencv.org/question/59383/find-a-square-of-points/?answer=59404#post-id-59404you can do the following
1. find all Regions in the image by
using findcontour
2. find center for every region, you
can use
[moments](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments)
, the center point will represent
the region
3. Pass the centers to Kmeans [Kmean
clustring](http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_ml/py_kmeans/py_kmeans_understanding/py_kmeans_understanding.html)
[or this
link](http://docs.opencv.org/master/d5/d38/group__core__cluster.html)
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)Thu, 09 Apr 2015 06:17:18 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/?answer=59404#post-id-59404Comment by antithing for <p>you can do the following</p>
<ol>
<li>find all Regions in the image by
using findcontour</li>
<li>find center for every region, you
can use
<a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments">moments</a>
, the center point will represent
the region</li>
<li><p>Pass the centers to Kmeans <a href="http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_ml/py_kmeans/py_kmeans_understanding/py_kmeans_understanding.html">Kmean <br/>
clustring</a>
<a href="http://docs.opencv.org/master/d5/d38/group__core__cluster.html">or this
link</a>
Kmean will find the clusters group of points </p></li>
<li><p>For every cluster You can use one of the following function todetect the rectangle(boundingRect, approxPolyDP,rotatedRect)</p></li>
</ol>
http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59407#post-id-59407Thanks! 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.Thu, 09 Apr 2015 07:03:13 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59407#post-id-59407Comment by antithing for <p>you can do the following</p>
<ol>
<li>find all Regions in the image by
using findcontour</li>
<li>find center for every region, you
can use
<a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments">moments</a>
, the center point will represent
the region</li>
<li><p>Pass the centers to Kmeans <a href="http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_ml/py_kmeans/py_kmeans_understanding/py_kmeans_understanding.html">Kmean <br/>
clustring</a>
<a href="http://docs.opencv.org/master/d5/d38/group__core__cluster.html">or this
link</a>
Kmean will find the clusters group of points </p></li>
<li><p>For every cluster You can use one of the following function todetect the rectangle(boundingRect, approxPolyDP,rotatedRect)</p></li>
</ol>
http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59409#post-id-59409found it here:
http://answers.opencv.org/question/36751/kmeans-clustering-for-vectorpoint2f-data-structure/
thanks again!Thu, 09 Apr 2015 07:59:02 -0500http://answers.opencv.org/question/59383/find-a-square-of-points/?comment=59409#post-id-59409