Opencv hough circle not detecting circles












1














I am trying to detect the circle inside traffic light, and I am able to detect only 1 out of the 2 circle, and the size of the circle which i am getting seems to be too big



Input Image: https://i.imgur.com/VkNDt2B.png



Output image: https://i.imgur.com/BBq5tE0.png



int main()
{
Mat src, gray;
src = imread("C:/test_image2.png", 1);
resize(src, src, Size(640, 480));

cvtColor(src, gray, CV_BGR2GRAY);

// Reduce the noise so we avoid false circle detection
GaussianBlur(gray, gray, Size(9, 9), 2, 2);

vector<Vec3f> circles;

// Apply the Hough Transform to find the circles
HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 1, 60, 200, 20, 0, 35);

// Draw the circles detected
for (size_t i = 0; i < circles.size(); i++)
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);// circle center
circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);// circle outline
cout << "center : " << center << "nradius : " << radius << endl;
}

// Show your results
namedWindow("Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE);
imshow("Hough Circle Transform Demo", src);

waitKey(0);
return 0;
}









share|improve this question





























    1














    I am trying to detect the circle inside traffic light, and I am able to detect only 1 out of the 2 circle, and the size of the circle which i am getting seems to be too big



    Input Image: https://i.imgur.com/VkNDt2B.png



    Output image: https://i.imgur.com/BBq5tE0.png



    int main()
    {
    Mat src, gray;
    src = imread("C:/test_image2.png", 1);
    resize(src, src, Size(640, 480));

    cvtColor(src, gray, CV_BGR2GRAY);

    // Reduce the noise so we avoid false circle detection
    GaussianBlur(gray, gray, Size(9, 9), 2, 2);

    vector<Vec3f> circles;

    // Apply the Hough Transform to find the circles
    HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 1, 60, 200, 20, 0, 35);

    // Draw the circles detected
    for (size_t i = 0; i < circles.size(); i++)
    {
    Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    int radius = cvRound(circles[i][2]);
    circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);// circle center
    circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);// circle outline
    cout << "center : " << center << "nradius : " << radius << endl;
    }

    // Show your results
    namedWindow("Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE);
    imshow("Hough Circle Transform Demo", src);

    waitKey(0);
    return 0;
    }









    share|improve this question



























      1












      1








      1







      I am trying to detect the circle inside traffic light, and I am able to detect only 1 out of the 2 circle, and the size of the circle which i am getting seems to be too big



      Input Image: https://i.imgur.com/VkNDt2B.png



      Output image: https://i.imgur.com/BBq5tE0.png



      int main()
      {
      Mat src, gray;
      src = imread("C:/test_image2.png", 1);
      resize(src, src, Size(640, 480));

      cvtColor(src, gray, CV_BGR2GRAY);

      // Reduce the noise so we avoid false circle detection
      GaussianBlur(gray, gray, Size(9, 9), 2, 2);

      vector<Vec3f> circles;

      // Apply the Hough Transform to find the circles
      HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 1, 60, 200, 20, 0, 35);

      // Draw the circles detected
      for (size_t i = 0; i < circles.size(); i++)
      {
      Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
      int radius = cvRound(circles[i][2]);
      circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);// circle center
      circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);// circle outline
      cout << "center : " << center << "nradius : " << radius << endl;
      }

      // Show your results
      namedWindow("Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE);
      imshow("Hough Circle Transform Demo", src);

      waitKey(0);
      return 0;
      }









      share|improve this question















      I am trying to detect the circle inside traffic light, and I am able to detect only 1 out of the 2 circle, and the size of the circle which i am getting seems to be too big



      Input Image: https://i.imgur.com/VkNDt2B.png



      Output image: https://i.imgur.com/BBq5tE0.png



      int main()
      {
      Mat src, gray;
      src = imread("C:/test_image2.png", 1);
      resize(src, src, Size(640, 480));

      cvtColor(src, gray, CV_BGR2GRAY);

      // Reduce the noise so we avoid false circle detection
      GaussianBlur(gray, gray, Size(9, 9), 2, 2);

      vector<Vec3f> circles;

      // Apply the Hough Transform to find the circles
      HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 1, 60, 200, 20, 0, 35);

      // Draw the circles detected
      for (size_t i = 0; i < circles.size(); i++)
      {
      Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
      int radius = cvRound(circles[i][2]);
      circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);// circle center
      circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);// circle outline
      cout << "center : " << center << "nradius : " << radius << endl;
      }

      // Show your results
      namedWindow("Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE);
      imshow("Hough Circle Transform Demo", src);

      waitKey(0);
      return 0;
      }






      c++ opencv image-processing hough-transform






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 2:58

























      asked Nov 11 at 2:48









      adi

      103




      103
























          2 Answers
          2






          active

          oldest

          votes


















          0














          HoughCircles works best if you know in advance the approx size of the circles you're looking for. I suggest you give a better value for min_radius and max_radius parameters.
          In any case, you need to play with param1 and param2 parameters. If circles are not perfect circles you can try to lower the image resolution using the dp parameter (f.ex. with dp = 2 the image is downscaled to half its resolution).
          Basically: play with param1 and param2 until your circles are detected, no matter if other circles are detected. Use this result to find out what radius your circles are, then fix the min and max radius to remove most circles you don't want and finally play again with param1 and param2 until only your circles are left.






          share|improve this answer





























            0














            this is a pretty huge image
            try cropping to the traffic light part first ( to get something to begin with ) and then by trying different combinations of min_distance and param_1,param_2 parameter try getting most circles ( even the wrong ones ) detected. find out what values get the most circles and what combination gets least ( or no ) circles and then fine tune the parameters to get lesser circles detected and finally find the perfect combination






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245421%2fopencv-hough-circle-not-detecting-circles%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              HoughCircles works best if you know in advance the approx size of the circles you're looking for. I suggest you give a better value for min_radius and max_radius parameters.
              In any case, you need to play with param1 and param2 parameters. If circles are not perfect circles you can try to lower the image resolution using the dp parameter (f.ex. with dp = 2 the image is downscaled to half its resolution).
              Basically: play with param1 and param2 until your circles are detected, no matter if other circles are detected. Use this result to find out what radius your circles are, then fix the min and max radius to remove most circles you don't want and finally play again with param1 and param2 until only your circles are left.






              share|improve this answer


























                0














                HoughCircles works best if you know in advance the approx size of the circles you're looking for. I suggest you give a better value for min_radius and max_radius parameters.
                In any case, you need to play with param1 and param2 parameters. If circles are not perfect circles you can try to lower the image resolution using the dp parameter (f.ex. with dp = 2 the image is downscaled to half its resolution).
                Basically: play with param1 and param2 until your circles are detected, no matter if other circles are detected. Use this result to find out what radius your circles are, then fix the min and max radius to remove most circles you don't want and finally play again with param1 and param2 until only your circles are left.






                share|improve this answer
























                  0












                  0








                  0






                  HoughCircles works best if you know in advance the approx size of the circles you're looking for. I suggest you give a better value for min_radius and max_radius parameters.
                  In any case, you need to play with param1 and param2 parameters. If circles are not perfect circles you can try to lower the image resolution using the dp parameter (f.ex. with dp = 2 the image is downscaled to half its resolution).
                  Basically: play with param1 and param2 until your circles are detected, no matter if other circles are detected. Use this result to find out what radius your circles are, then fix the min and max radius to remove most circles you don't want and finally play again with param1 and param2 until only your circles are left.






                  share|improve this answer












                  HoughCircles works best if you know in advance the approx size of the circles you're looking for. I suggest you give a better value for min_radius and max_radius parameters.
                  In any case, you need to play with param1 and param2 parameters. If circles are not perfect circles you can try to lower the image resolution using the dp parameter (f.ex. with dp = 2 the image is downscaled to half its resolution).
                  Basically: play with param1 and param2 until your circles are detected, no matter if other circles are detected. Use this result to find out what radius your circles are, then fix the min and max radius to remove most circles you don't want and finally play again with param1 and param2 until only your circles are left.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 at 8:16









                  L.C.

                  19012




                  19012

























                      0














                      this is a pretty huge image
                      try cropping to the traffic light part first ( to get something to begin with ) and then by trying different combinations of min_distance and param_1,param_2 parameter try getting most circles ( even the wrong ones ) detected. find out what values get the most circles and what combination gets least ( or no ) circles and then fine tune the parameters to get lesser circles detected and finally find the perfect combination






                      share|improve this answer


























                        0














                        this is a pretty huge image
                        try cropping to the traffic light part first ( to get something to begin with ) and then by trying different combinations of min_distance and param_1,param_2 parameter try getting most circles ( even the wrong ones ) detected. find out what values get the most circles and what combination gets least ( or no ) circles and then fine tune the parameters to get lesser circles detected and finally find the perfect combination






                        share|improve this answer
























                          0












                          0








                          0






                          this is a pretty huge image
                          try cropping to the traffic light part first ( to get something to begin with ) and then by trying different combinations of min_distance and param_1,param_2 parameter try getting most circles ( even the wrong ones ) detected. find out what values get the most circles and what combination gets least ( or no ) circles and then fine tune the parameters to get lesser circles detected and finally find the perfect combination






                          share|improve this answer












                          this is a pretty huge image
                          try cropping to the traffic light part first ( to get something to begin with ) and then by trying different combinations of min_distance and param_1,param_2 parameter try getting most circles ( even the wrong ones ) detected. find out what values get the most circles and what combination gets least ( or no ) circles and then fine tune the parameters to get lesser circles detected and finally find the perfect combination







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 12 at 8:26









                          hishaamhhh

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245421%2fopencv-hough-circle-not-detecting-circles%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              Xamarin.form Move up view when keyboard appear

                              Post-Redirect-Get with Spring WebFlux and Thymeleaf

                              Anylogic : not able to use stopDelay()