如何进行图像处理或机器学习来进行任务圈检测和比较

编程


我正在开发一个软件,我想要进行一些图像处理并从图像中检测圆圈,我想检测两个圆圈,第一个圆圈在对象(粗糙的钻石)中,第二个圆圈是我正在绘制的图像或视频框。
这里有一些图像,显示了该图像的类型 图片1
图片2
图3
图4

在上面的图像中,一个红色圆圈是我正在使用一些参数绘制的,而对象上的黑色圆圈是我想要检测以与我在视频框上绘制的圆圈进行比较或匹配的圆圈。

现在,检测完成后,我想比较或匹配我正在绘制的圆圈和我从图像处理中获得的圆圈。

所以我尝试了两天的图像处理仍然没有得到我想要的结果。
因此我必须考虑机器学习或人工智能
如果我可以提供匹配或不匹配圆圈的数据集,那么我可以在我的项目中使用人工智能或机器学习吗?
如果是,那么我该如何使用以及需要多少时间?

我尝试过的:

我已经尝试过 EmguCV 库并做了一些图像处理,但这仍然不准确,我仍然停留在检测物体上的黑色圆圈(粗糙的钻石)上

在这里我使用 emgucv 做了一些图像处理,但没有得到我想要的结果
我使用此代码得到的结果是:
图片1
图片2

注意:也适用于某些图像,但不适用于所有图像。

C#
// 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();

解决方案1

你好,
查看霍夫圆变换来检测圆。

コメント

タイトルとURLをコピーしました