How to get x,y position of contours in Python OpenCV
<p>I'm trying to get x and y positions of contours from the following image, but I messed up.
<a href="http://i.stack.imgur.com/ctBI9.png" rel="nofollow">the image</a></p>

<p>I just need to find x and y positions of contours or center of the contours.</p>

<p>The results will be something like the following as I manually look up their positions from GIMP.</p>

<p>290, 210
982, 190
570, 478 </p>

<p>I believe it can be done with cv2.findContours method, but I'm really out of ideas right now.</p>

<p>-Offtopic-</p>

<p>I will use these values in setting cursor position usingwin32api.SetCursorPos((xposition,yposition))</p>

<p>Thanks</p>

<p>Indeed, you can do that with <code>findContours</code>. Since you have your contours there are several options:</p>

<ol>
<li>Calculate enclosing rectangle and take e.g. the center point.</li>
<li>Calculate moments and take the centroid </li>
<li>Fit minimum enclosing circle and take the center</li>
<li>and so on...</li>
</ol>

<p><a href="http://docs.opencv.org/trunk/dd/d49/tutorial_py_contour_features.html" rel="nofollow">Here</a> are some examples of what you can do with your contours, including the options above. </p>

python opencv