gpt4 book ai didi

c# - 使用 C# 进行光学标记识别

转载 作者:太空宇宙 更新时间:2023-11-03 15:38:41 25 4
gpt4 key购买 nike

这是一个确定点是否在图像边界内并检查它是否与其他圆重叠的函数。

如果它返回 true,那么我检查填充黑色的圆的阈值,然后将填充超过 90% 的点保存到点列表中。

我的程序分两步运行

1) 如果它形成一个没有重叠的圆。

2) 如果是90%填充。

我遇到一个错误,如果我传递一张只有 1 个圆圈的图像,它会保存 1408 个圆圈。我不知道我做错了什么。

下面是按钮点击事件

        for (int i = 0; i < 50; i++)
{
for (int j = 0; j < 50; j++)
{
p.X = j;
p.Y = i;
if (isCircle(p))
{

if (checkThreshold(p) > 90)
{
pts.Insert(0, p);
}
}
}
}

下面是函数

private bool isCircle(Point p)
{

double count = 0;
Point curP = new Point();
//Point centre = new Point(24, 20);
int a = 0;

boundary.X = 50;
boundary.Y = 50;

for (int x = (p.X - radius); x <= (p.X - radius); x++)
{
for (int y = (p.Y - radius); y <= (p.Y - radius); y++)
{
if ((x < boundary.X) && (y < boundary.Y) && (x + radius < boundary.X) && (y + radius < boundary.Y))
{
curP.X = 0;
curP.Y = 0;

curP.X = x;
curP.Y = y; //stores new point to be sent in curP
while (a < pts.Count)
{
//point , centre, radius
if (checkOverlap(curP, pts[a], radius) == false) //send point to check if it overlaps or not
{
// MessageBox.Show("yellow");
count = 1;
break;
}
else
{
a++;
}

}

}
if (count == 1)
break;
}
if (count == 1)
break;

}

if (count == 1)
return true;

else return false;
}

下面给出的是checkOverlap函数

    private bool checkOverlap(Point p, Point c, int radii)
{

Point listPoint;

listPoint = p;

//the following if condition checks if the point resides in the list or not

if ((((c.X - radii) < listPoint.X) && (listPoint.X > (c.X - radii))) && (((c.Y - radii) < listPoint.Y) && (listPoint.Y > (c.Y - radii))))
{
if ((((p.X - c.X) * (p.X - c.X)) - ((p.Y - c.Y) * (p.Y - c.Y))) < (radius * radius))
{
return false;
}
return true;
}
else
return true;
}

最佳答案

不确定这是否是问题所在,但由于您测试相等性的方式,您的 count 变量应该是一个 int

关于c# - 使用 C# 进行光学标记识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30974876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com