Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:40:52+00:00 2026-05-26T02:40:52+00:00

I am trying to detect 22 balls on the snooker table. I have an

  • 0

I am trying to detect 22 balls on the snooker table. I have an image to test on but programme os detecting 2 balls, and random circles elsewhere. My code is below with the circle detection algorithm. Does anyone know which parameters should be adjusted to get the detection i would need? thanks

#include <cv.h>
#include <highgui.h>
#include <math.h>

int main(int argc, char** argv)
{   int edge_thresh = 1;
    IplImage* img = cvLoadImage("C:\\Users\\Nathan\\Desktop\\SnookerPic.png", 1);;
    IplImage* gray = cvCreateImage(cvGetSize(img), 8, 1);
     IplImage *edge = cvCreateImage( cvSize(img->width,img->height), 8, 1);
    CvMemStorage* storage = cvCreateMemStorage(0);
    cvCvtColor(img, gray, CV_BGR2GRAY);
    cvThreshold(gray,gray, CV_GAUSSIAN, 9, 9);
    cvSmooth(gray, gray, CV_GAUSSIAN, 11, 11); 
    cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 5);
    CvSeq* circles = cvHoughCircles(edge, storage, 
        CV_HOUGH_GRADIENT, 2, 20, 200, 50);
    int i;

    for (i = 0; i < circles->total; i++) 
    {
         float* p = (float*)cvGetSeqElem( circles, i );
         cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 
             3, CV_RGB(0,255,0), -1, 8, 0 );
         cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 
             cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
    }
    cvNamedWindow( "circles", 1 );
    cvShowImage( "circles", img );


    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:40:52+00:00Added an answer on May 26, 2026 at 2:40 am

    I suspect you are having trouble with the parameters being either too restrictive or loose. You need to play with the parameters until you get the number of circles you want. Also, the Gaussian 11×11 blur may be a bit aggressive depending on the image. For my image, it was doing more harm than good, but my image is kind of idealized…

    I modified the OpenCV example you are using to include the track bars allowing you to play with the Canny parameters. This should really help you get a feel for how it works. Also, pay attention to the minDist parameter. For my image, the circle centers were about 32 pixels away. You’ll need to adjust this to your circle sizes. So, here is the sample:

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    
    using namespace cv;
    
    int hi = 1, lo = 1;
    
    int main(int argc, char* argv[]) {
        Mat orig = imread("Snooker_balls_triangled.png");
        int key = 0;
    
        namedWindow("circles", 1);
        createTrackbar("hi", "circles", &hi, 255);
        createTrackbar("lo", "circles", &lo, 255);
    
        do
        {
            // update display and snooker, so we can play with them
            Mat display = orig.clone();
    
            Mat snooker;
            cvtColor(orig, snooker, CV_RGB2GRAY);
    
            vector<Vec3f> circles;
    
            // also preventing crash with hi, lo threshold here...
            HoughCircles(snooker, circles, CV_HOUGH_GRADIENT, 2, 32.0, hi > 0 ? hi : 1, lo > 0 ? lo : 1 );
            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]);
    
                 // draw the green circle center
                 circle( display, center, 3, Scalar(0,255,0), -1, 8, 0 );
    
                 // draw the blue circle outline
                 circle( display, center, radius, Scalar(255,0,0), 3, 8, 0 );
            }
    
            imshow( "circles", display );
            imshow("snooker", snooker);
            key = waitKey(33);
        } while((char)key != 27);
        return 0;
    }
    

    I used this snooker image, and this is the output I get.

    (P.S. consider using the C++ interface it’s far superior to the C interface IMHO 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code is straightforward. i am trying to detect 22 balls but ionly getting
I'm trying to detect the positions of billiards balls on a table from an
I'm trying to detect an occurrence of a string within string. But the code
Trying to detect left click vs right click (without using jQuery!) and I have
I'm trying to detect pinch using multitouch in onTouchEvent of the activity. But the
I'm trying to detect whether a string holds a dash but nothing seems to
I'm trying to detect line segments in an image. From what I gather, the
I've been trying to detect click on a Gtk::Image with gtkmm for over 2
i am trying to detect Collision of two sprites in the following way...but when
I am trying to detect text between 3 or 4 tags and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.