1.获取扫描仪的新增图。通过判断扫描仪扫描的文件夹内文件数量来判断。
void Update()
{
if (Time.time - m_CheckNewImageTime > 5f)
{
CheckNewImage();
m_CheckNewImageTime = Time.time;
}
}
/// <summary>
/// 检查新图片
/// </summary>
private void CheckNewImage()
{
if (!m_ShouldCheckNewImag) return;
List<string> allImageNamesInFolder = GetAllImageNamesInFolder(srcFolder);
foreach (var text in allImageNamesInFolder)
{
if (!m_ImageDic.ContainsKey(text) && !text.Contains("resize") && !text.Contains("sign")
&& !text.Contains("code") && !text.Contains("seed") && !text.Contains("mark"))
{
LoadNewImage(text);
// print(text+" text");
break;
}
}
}
2.识别新增的图是哪一种鱼
原理:通过识别图片四个区域的颜色填充来判断是哪种鱼。
如图,四个识别点位是 1,1,0,1 可判断为海豚。
/// <summary>
/// 识别哪种图片
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
private uint GetCharactorType(Bitmap bitmap)
{
uint num = IsBlack(bitmap, new Vector2(70f, 85f));
uint num2 = IsBlack(bitmap, new Vector2(965f, 85f));
uint num3 = IsBlack(bitmap, new Vector2(70f, 925f));
uint num4 = IsBlack(bitmap, new Vector2(965f, 925f));
Debug.Log(string.Concat(new object[]{
"u0: ",
num,
" u1 : ",
num2,
" u2 : ",
num3,
" u3 : ",
num4
}
));
uint result = num | num2 << 1 | num3 << 2 | num4 << 3;
Debug.Log("-------------------------");
Debug.Log("GetCharactorType: " + result.ToString("X2"));
return result;
}
/// <summary>
/// 看这个点的20范围 像素是否是黑色的
/// </summary>
/// <param name="bitmap"></param>
/// <param name="pos"></param>
/// <returns></returns>
private uint IsBlack(Bitmap bitmap, Vector2 pos)
{
if (pos.x < 0f || pos.x > (float)bitmap.Size.Width || pos.y < 0f || pos.y > (float)bitmap.Size.Height)
{
Debug.Log("ImageScan IsBlack out of Size@");
return 0u;
}
int num = 20;
int num2 = 0;
int num3 = 1;
for (int i = -num; i < num; i++)
{
for (int j = -num; j < num; j++)
{
System.Drawing.Color pixel = bitmap.GetPixel((int)(pos.x + (float)(i * num3)), (int)(pos.y + (float)(j * num3)));
if ((float)(pixel.R + pixel.G + pixel.B) / 3f < 127.5f)
{
num2++;
}
bitmap.SetPixel((int)(pos.x + (float)(i * num3)), (int)(pos.y + (float)(j * num3)), System.Drawing.Color.Red);
}
}
float num4 = (float)num2 / ((float)(num * num) * 4f);
// Debug.Log("IsBlack:" + num4);
return (num4 <= 0.3f) ? 0u : 1u;
}
识别四个点后 判断
public static CreaterType GetCreaterType(uint mark)
{
switch (mark)
{
case 1u:
return CreaterType.eType_HAIGUI;
case 2u:
return CreaterType.eType_HAIMA;
case 3u:
return CreaterType.eType_HUDIEYU;
case 5u:
return CreaterType.eType_JINGQIANGYU;
case 6u:
return CreaterType.eType_CHOUYU;
case 7u:
return CreaterType.eType_HETUN;
case 8u:
return CreaterType.eType_WUZEI;
case 9u:
return CreaterType.eType_JIANYU;
case 10u:
return CreaterType.eType_SHAYU;
case 11u:
return CreaterType.eType_HAITUN;
}
return CreaterType.e_None;
}