Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First to select the polygon use <a href="http://docs.opencv.org/modules/highgui/doc/user_interface.html#setmousecallback" rel="nofollow">setMouseCallback</a> to get a callback every time the user clicks on the image. Add each clicked point to a list of your polygon-points. To visualize the points so far you can use the <a href="http://docs.opencv.org/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.html" rel="nofollow">drawing functions in OpenCV</a>. There is also some sample code on how to use setMouseCallback <a href="http://code.opencv.org/projects/opencv/repository/revisions/master/entry/samples/cpp/ffilldemo.cpp" rel="nofollow">here</a>. You can for example let the user pick points until he presses a button or uses right click for the last point to finish picking.</p> <p>To use the resulting polygon look at the tutorial <a href="http://www.pieter-jan.com/node/5" rel="nofollow">here</a>. Additionally after this you could also use <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=boundingrect#boundingrect" rel="nofollow">boundingRect</a> to crop the image around the polygon.</p> <p>Edit: Just realized that it is probably smarter to use <a href="http://docs.opencv.org/modules/core/doc/drawing_functions.html#fillpoly" rel="nofollow">fillPoly</a> to create the mask.</p> <pre><code>vector&lt;vector&lt;cv::Point&gt; &gt; polygons; // draw function takes list of polygons cv::Mat mask = cv::Mat::zeros(height, width, CV_8UC3); cv::fillPoly(mask, polygons, cv::Scalar(255, 255, 255)); </code></pre> <p>It seems the above code is not documented (however it works at least in an older version of Opencv 2.3.1). Another way of doing it is this:</p> <pre><code>cv::Mat mask = cv::Mat::zeros(height, width, CV_8UC3); // Image vector&lt;vector&lt;cv::Point&gt; &gt; polygons; // draw function takes list of polygons vector&lt;int&gt; polygonSizes; vector&lt;cv::Point*&gt; polygonPointers; for (int i=0; i&lt;polygons.size(); i++) { polygonSizes.push_back(polygons[i].size()); polygonPointers.push_back(&amp;polygons[i][0]); } cv::fillPoly(mask, (const cv::Point**) &amp;polygonPointers[0], &amp;polygonSizes[0], (int)polygons.size(), cv::Scalar(255, 255, 255)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload