Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>cv::findcontours returns every contour as a vector of points (see <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours" rel="noreferrer">http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours</a>).</p> <p>You have to convert these vectors to your data structure (Component) by yourself like in this minimal example I created:</p> <pre><code>#include &lt;opencv2/opencv.hpp&gt; #include &lt;iostream&gt; struct Component { cv::Rect boundingBox; double area; double circularity; }; int main() { // Create a small image with a circle in it. cv::Mat image(256, 256, CV_8UC3, cv::Scalar(0, 0, 0)); cv::circle(image, cv::Point(80, 110), 42, cv::Scalar(255,127, 63), -1); // Find canny edges. cv::Mat cannyEdges; cv::Canny(image, cannyEdges, 80, 60); // Show the images. cv::imshow("img", image); cv::imshow("cannyEdges", cannyEdges); // Find the contours in the canny image. cv::vector&lt;cv::Vec4i&gt; hierarchy; // "Each contour is stored as a vector of points." // http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours typedef cv::vector&lt;cv::vector&lt;cv::Point&gt; &gt; TContours; TContours contours; cv::findContours(cannyEdges, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE); // cannyEdges is destroyed after calling cv::findContours // Print number of found contours. std::cout &lt;&lt; "Found " &lt;&lt; contours.size() &lt;&lt; " contours." &lt;&lt; std::endl; // Convert contours to Components. typedef cv::vector&lt;Component&gt; TComponents; TComponents components; for (TContours::const_iterator it( contours.begin() ); it != contours.end(); ++it) { Component c; c.area = cv::contourArea(*it); c.boundingBox = cv::boundingRect(*it); c.circularity = 0.0; // Insert whatever you mean by circularity; components.push_back(c); } for (TComponents::const_iterator it( components.begin() ); it != components.end(); ++it) std::cout &lt;&lt; it-&gt;area &lt;&lt; std::endl; // and whatever you want. // Wait for user input. cv::waitKey(); } </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.
    3. 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