Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <code>houghCircle</code> directly on your image, don't extract edges first. Then test for each detected circle, how much percentage is really present in the image:</p> <pre><code>int main() { cv::Mat color = cv::imread("../houghCircles.png"); cv::namedWindow("input"); cv::imshow("input", color); cv::Mat canny; cv::Mat gray; /// Convert it to gray cv::cvtColor( color, gray, CV_BGR2GRAY ); // compute canny (don't blur with that image quality!!) cv::Canny(gray, canny, 200,20); cv::namedWindow("canny2"); cv::imshow("canny2", canny&gt;0); std::vector&lt;cv::Vec3f&gt; circles; /// Apply the Hough Transform to find the circles cv::HoughCircles( gray, circles, CV_HOUGH_GRADIENT, 1, 60, 200, 20, 0, 0 ); /// Draw the circles detected for( size_t i = 0; i &lt; circles.size(); i++ ) { Point center(cvRound(circles[i][0]), cvRound(circles[i][1])); int radius = cvRound(circles[i][2]); cv::circle( color, center, 3, Scalar(0,255,255), -1); cv::circle( color, center, radius, Scalar(0,0,255), 1 ); } //compute distance transform: cv::Mat dt; cv::distanceTransform(255-(canny&gt;0), dt, CV_DIST_L2 ,3); cv::namedWindow("distance transform"); cv::imshow("distance transform", dt/255.0f); // test for semi-circles: float minInlierDist = 2.0f; for( size_t i = 0; i &lt; circles.size(); i++ ) { // test inlier percentage: // sample the circle and check for distance to the next edge unsigned int counter = 0; unsigned int inlier = 0; cv::Point2f center((circles[i][0]), (circles[i][1])); float radius = (circles[i][2]); // maximal distance of inlier might depend on the size of the circle float maxInlierDist = radius/25.0f; if(maxInlierDist&lt;minInlierDist) maxInlierDist = minInlierDist; //TODO: maybe paramter incrementation might depend on circle size! for(float t =0; t&lt;2*3.14159265359f; t+= 0.1f) { counter++; float cX = radius*cos(t) + circles[i][0]; float cY = radius*sin(t) + circles[i][1]; if(dt.at&lt;float&gt;(cY,cX) &lt; maxInlierDist) { inlier++; cv::circle(color, cv::Point2i(cX,cY),3, cv::Scalar(0,255,0)); } else cv::circle(color, cv::Point2i(cX,cY),3, cv::Scalar(255,0,0)); } std::cout &lt;&lt; 100.0f*(float)inlier/(float)counter &lt;&lt; " % of a circle with radius " &lt;&lt; radius &lt;&lt; " detected" &lt;&lt; std::endl; } cv::namedWindow("output"); cv::imshow("output", color); cv::imwrite("houghLinesComputed.png", color); cv::waitKey(-1); return 0; } </code></pre> <p>For this input:</p> <p><img src="https://i.stack.imgur.com/bnxiX.png" alt="enter image description here"></p> <p>It gives this output:</p> <p><img src="https://i.stack.imgur.com/7jVXC.png" alt="enter image description here"></p> <p>The red circles are Hough results.</p> <p>The green sampled dots on the circle are inliers.</p> <p>The blue dots are outliers.</p> <p>Console output:</p> <pre><code>100 % of a circle with radius 27.5045 detected 100 % of a circle with radius 25.3476 detected 58.7302 % of a circle with radius 194.639 detected 50.7937 % of a circle with radius 23.1625 detected 79.3651 % of a circle with radius 7.64853 detected </code></pre> <p>If you want to test RANSAC instead of Hough, have a look at <a href="http://www.dcs.warwick.ac.uk/bmvc2007/proceedings/CD-ROM/papers/paper-260.pdf" rel="nofollow noreferrer">this</a>.</p>
    singulars
    1. This table or related slice is empty.
    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