我有以下图片:
https://www.upsieutoc.com/images/2014/10/18/binkq27dd30.png
我想计算图像中有多少个圆圈。我的图像是nxn 8位二进制图像,而不是0和1。 那么,我能做什么呢? 感谢您的阅读!
最佳答案
精简版:http://www.codeproject.com/Articles/36378/Optical-Mark-Recognition-with-DotImage
//Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("Answers.jpg");
//Check the pixels in the Bitmap for the circles:
for (int i = 0; i < myBitmap.Width;i++)
{
for (int j = 0; j < myBitmap.Height;j++)
{
Color pixelColor = myBitmap.GetPixel(i, j);
//Translate pixel to a 1 or 0 depending on if the pixel is black or white
//This next line is psuedo code:
boolArray[i][j] = pixelColour.R < 128 && pixelColour.G < 128 && pixelColour.B < 128;
}
}
然后迭代 bool 数组,查看一行中以及上方和下方是否有三个或四个 1,例如:
if (boolArray[i][j] && boolArray[i + 1][j] && boolArray[i + 2][j])
{
if (boolArray[i][j + 1] && boolArray[i][j + 2] && boolArray[i][j + 3])
{
//found an answer marked as a filled in circle
}
}
注意:您应该检查同一嵌套循环中的 cicle。我只填充了一个多维 bool 数组,以便您可以看到这两个逻辑。
关于c# - 如何检测二值图像RGB中的圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26435974/