c# 关于找图问题 -------问题代码 求修改 求解 F5 已烂
public Point GetImageContains(Bitmap p_SourceBitmap, Bitmap p_PartBitmap, int p_Float,int pointnums)
{
Point P_res = new Point(-1, -1);
int Height_S = p_SourceBitmap.Height;
int Width_S = p_SourceBitmap.Width;
int Height_P = p_PartBitmap.Height;
int Width_P = p_PartBitmap.Width;
//原图转换成 byte[]
BitmapData _SourceData = p_SourceBitmap.LockBits(new Rectangle(0, 0, p_SourceBitmap.Width, p_SourceBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte[] DataSource = new byte[_SourceData.Stride * p_SourceBitmap.Height];
Marshal.Copy(_SourceData.Scan0, DataSource, 0, DataSource.Length);
p_SourceBitmap.UnlockBits(_SourceData);
//子图转换成 byte[]
BitmapData _PartData = p_PartBitmap.LockBits(new Rectangle(0, 0, p_PartBitmap.Width, p_PartBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte[] DataPart = new byte[_PartData.Stride * p_PartBitmap.Height];
Marshal.Copy(_PartData.Scan0, DataPart, 0, DataPart.Length);
p_PartBitmap.UnlockBits(_PartData);
int index=0;
for (int b = 0; b < Height_S - Height_P; b++)
for (int a = 0; a < Width_S - Width_P; a++)
{
//5点 分别为左上 右上 中间 左下 右下
index = (b * Width_S + a) * 4;
bool b1 = ScanColor(DataSource[index], DataSource[index + 1], DataSource[index + 2], DataPart[0], DataPart[1], DataPart[2], p_Float);
if (!b1) continue;
Point tempp = new Point(a, b);
int p2 = (Width_P - 1) * 4;
b1 = ScanColor(DataSource[index + p2], DataSource[index + 1 + p2], DataSource[index + 2 + p2], DataPart[p2], DataPart[p2 + 1], DataPart[p2 + 2], p_Float);
if (!b1) continue;
tempp = new Point(a, b + Width_P);
p2 = ((Height_P / 2) * Width_P + (Width_P / 2)) * 4;
int p3 = ((b + (Height_P / 2)) * Width_S + (a + (Width_P / 2))) * 4;
b1 = ScanColor(DataSource[p3], DataSource[p3 + 1], DataSource[p3 + 2], DataPart[p2], DataPart[p2 + 1], DataPart[p2 + 2], p_Float);
if (!b1) continue;
p2 = ((Height_P - 1) * Width_P) * 4;
p3 = ((b + (Height_P - 1)) * Width_S + a) * 4;
b1 = ScanColor(DataSource[p3], DataSource[p3 + 1], DataSource[p3 + 2], DataPart[p2], DataPart[p2 + 1], DataPart[p2 + 2], p_Float);
if (!b1) continue;
p2 = (Height_P * Width_P - 1) * 4;
p3 = ((b + Height_P) * Width_S + (a + Width_P) - 1) * 4;
b1 = ScanColor(DataSource[p3], DataSource[p3 + 1], DataSource[p3 + 2], DataPart[p2], DataPart[p2 + 1], DataPart[p2 + 2], p_Float);
if (!b1) continue;
else
{
//5点匹配 则匹配其余的点
if (ImgDb(index, DataSource, DataPart, p_Float, pointnums))
{
P_res = new Point(a, b);
break;
}
else
P_res = new Point(-1, -1);
}
}
return P_res;
}
private bool ImgDb(int index, byte[] DataImage, byte[] DataPart, int p_Float, int pointnums)
{
int tempint = pointnums;
for (int i = index; i < (DataPart.Length + index); i+=4)
{
bool b3 = ScanColor(DataImage[index], DataImage[index + 1], DataImage[index + 2], DataPart[i - index], DataPart[i - index + 1], DataPart[i - index + 2], p_Float);
if (!b3 && tempint > 0)
{
tempint--;
}
else if (!b3)
return false;
}
return true;
}
private static bool ScanColor(int r1,int g1,int b1,int r2,int g2,int b2, int p_Float)
{
return (r1 <= (r2 + p_Float) && (r1 >= r2 - p_Float)) && ((g1 <= g2 + p_Float) && g1 >= (g2 - p_Float)) && (b1 <= (b2 + p_Float) && (b1 >= b2 - p_Float));
}
以上代码有 写错的地方 貌似是 ImgDb 方法 求解
...全文
相关推荐
求e的近似值.zip 经典问题 c#
爱经典,爱编程!本程序用的是c#语言编写的,windows程序界面,很有参考价值哦!
JPEG隐写术的F5算法的C#实现
隐写术是一种隐藏信息的技术,它将信息隐藏在其他媒体中,如图像、音频或视频文件。在本文中,我们将探讨JPEG隐写术的F5算法,并提供其C#实现的详细步骤。F5算法是一种高效的隐写术算法,它使用了JPEG文件的特性来隐藏信息。这种算法的主要优点是它可以在不显著改变图像质量的情况下隐藏大量的信息。在C#中实现F5算法需要对JPEG文件格式和隐写术的基本原理有深入的理解。首先,我们需要了解JPEG文件是如何存储图像数据的。JPEG文件由多个部分组成,包括文件头、图像数据和文件尾。
三点求圆心_三点求圆心_三个点求圆心_3点求圆心_圆心_求圆心_
通过三个点坐标,求出圆心坐标。C#代码,主要是算法。
8 puzzle 问题 C# 代码
8 puzzle问题, C# 代码,算法设计与分析课程作业,实现简单的8 puzzle游戏,适合初学者
C#求二元一次方程界面版
c#求二元一次方程界面版,完美运行


