8

What to do image processing or machine learning for task circle detect and compa...

 1 year ago
source link: https://www.codeproject.com/Questions/5365892/What-to-do-image-processing-or-machine-learning-fo
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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
Image2
Image3
Image4
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 :
image1
image2
note: also works for some of the images not for all.

Expand ▼  
// 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();

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK