title: Opencv: false number of vertices of a circle
body: <p>Im struggling with the shape detection using OpenCV for C++. The edged figures such as triangle and rectangular are detected trouble-free. But when it comes to circle it estimates number of vertices up to 6-8. Could somebody help me?</p>
  <pre><code>void getContours(Mat video){
      Mat grayscale, canny_output;
      cvtColor(video, grayscale,COLOR_RGB2GRAY);//converting image to grayscale
      GaussianBlur(grayscale, grayscale, Size(9, 9), 2, 2 );
      threshold(grayscale, grayscale,60,255,THRESH_BINARY);
      vector &lt;vector&lt;Point&gt;&gt; contours, output_contour;
      vector &lt;Vec4i&gt; hierarchy;
      findContours( grayscale, contours, hierarchy, RETR_TREE,CHAIN_APPROX_SIMPLE );
      Mat drawing = Mat::zeros( grayscale.size(), CV_8UC3 );
      vector&lt;Point&gt; c; 
      for (size_t i = 0; i&lt;contours.size(); i++){
          c = contours[i];
          Rect crect = boundingRect(c);
          // compute the center of the contour, then detect the name of the
          // shape using only the contour
          Moments M = moments(c);
          int cX, cY;
          cX = static_cast&lt;int&gt;(M.m10/M.m00);
          cY = static_cast&lt;int&gt;(M.m01/M.m00);
          string shape = detect(Mat(c));
          drawContours( drawing, contours, (int)i, Scalar(0, 255, 0), 2);
          Point pt(cX,cY);
          putText(drawing,shape,pt, FONT_HERSHEY_SIMPLEX, 0.5, Scalar(255, 255, 255), 2);
          imshow(&quot;contour&quot;, drawing);
          
      }
  }
  </code></pre>
  <pre><code>string detect(const Mat &amp;curve){
      string shape = &quot;unidentified&quot;;
      double peri = arcLength(curve, true);
      Mat approx;
      approxPolyDP(curve, approx, 0.04 * peri, true); // 0.01~0.05
      const int num_of_vertices = approx.rows;
      if(num_of_vertices == 0){
          shape = &quot;circle&quot;;
          
      }
      if(num_of_vertices==2){
          shape = &quot;line&quot;; 
      }
      cout&lt;&lt;&quot;\n&quot;&lt;&lt;num_of_vertices;
      return to_string(num_of_vertices);
  
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/142pD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/142pD.jpg" alt="example of false detection. The 4 is the vertices of the window itself" /></a></p>