Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am working on a software where i want to do some image processing and detect the circle from the image and there is two circles that i want to detect first one is in the object (rough diamond) and the second one is i am drawing on the image or video box.
here are some images of which type of the image it will be Image1
here in above images one red circle is i am drawing using some parameters and the black circle that are on the object is the circle i want to detect for compare or to match with circle that i have drawn on the video box.

now after the detection is complete i want to compare or match the circles that i am drawing and the circle that i get from the image processing from the image.

so i am trying image processing from 2 days still did not get the result i want.
thus i have to think about Machine Learning Or AI
if i can provide data set of matched or not matched circles then can i use the AI or Machine learning for my project?
if yes then how can i use and how much time is needed for this?

What I have tried:

i have tried EmguCV Library and done some image processing but this is not accurate still i am stuck on just detection of the black circle on the object(rough diamond)

here i have done some image processing using emgucv but did not getting the result i want
results i got using this code is :
note: also works for some of the images not for all.

// Convert the image to grayscale
            Image<Gray, byte> grayImage = originalImage.Convert<Gray, byte>();
            pictureBox1.Image = grayImage.ToBitmap();

            // Apply Gaussian blur
            CvInvoke.GaussianBlur(grayImage, grayImage, new Size(5, 5), 0);
            pictureBox2.Image = grayImage.ToBitmap();

            // Threshold the grayscale image to isolate black circles
            double thresholdValue = 70; // Adjust this value based on the intensity of your black circles
            Image<Gray, byte> binaryImage = grayImage.ThresholdBinary(new Gray(thresholdValue), new Gray(255));
            pictureBox3.Image = binaryImage.ToBitmap();

            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
            Mat hierarchy = new Mat();

            CvInvoke.FindContours(binaryImage, contours, hierarchy, RetrType.List, ChainApproxMethod.ChainApproxSimple);

            // Loop through all detected contours
            for (int i = 0; i < contours.Size; i++)
                using (VectorOfPoint contour = contours[i])
                    double area = CvInvoke.ContourArea(contour);
                    double perimeter = CvInvoke.ArcLength(contour, true);

                    // Calculate circularity (4 * π * area / perimeter^2)
                    double circularity = (4 * Math.PI * area) / (perimeter * perimeter);

                    // Check if the contour is a perfect circle based on circularity
                    if (circularity > 0.8 && contour.Size > 150) // Adjust the circularity threshold and minimum number of vertices as needed
                        CircleF circle = CvInvoke.MinEnclosingCircle(contour);
                        originalImage.Draw(circle, new Bgr(Color.Red), 2); // You can change the color and thickness of the circle here

            pictureBox.Image = originalImage.ToBitmap();
[no name] 1-Aug-23 11:32am    
If I was going to do it "by hand" (which I do), I would include parameters line "min and max" radius; center point offset; background and foreground colors. I would then radiate circles from the estimated center point until one start to align (the circle "strokes" are a different size so one should fit within the other ... i.e. the background color changes). So, you need a routine that can walk a pixel in a circle and test the underlying image pixels for a certain accuracy % that indicates a circle. (It's sounds like alot of CPU but it really isn't)
OzzieOzburn 10-Sep-23 15:52pm    
I would apply canny or sobel edge detection and then i would try to exract the pixel numbers of dedected edges to compare with your own draw circle.

1 solution

Have a look for Hough Circle Transform to detect circle.
Share this answer
sahil ajmeri 2022 2-Aug-23 3:31am    
okay i have use Hough Circle Transformation and after modifying some values of parameters i am able to detect circle but the accuracy of the perfect detection is still missing somewhere. i have some sample images are :

some of the detection of circles are accurate like some circle lines did not match whole part of circle

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900