|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
using o0.Geometry2D.Float;
|
|
|
using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Threading.Tasks;
|
|
|
@@ -618,7 +619,7 @@ namespace o0.Project
|
|
|
//读取数据
|
|
|
if (debugImage != null)
|
|
|
{
|
|
|
- Debug.Log($"Debug {debugImage.name}");
|
|
|
+ Debug.Log($"<color=aqua>Debug {debugImage.name}</color>");
|
|
|
differPixel = debugImage.GetPixels();
|
|
|
}
|
|
|
else // 获得屏幕差值
|
|
|
@@ -666,7 +667,24 @@ namespace o0.Project
|
|
|
Debug.Log($"[ScreenIdentification] Size: ({Size.x},{Size.y}), 卷积核Size: {conSize}, 最小线段长度: {minLength}");
|
|
|
var (edge, edgeDir) = ScreenLocateTexLightedMat.zimIdentifyEdgeGradientAny(conSize);
|
|
|
|
|
|
- var quadLines = ScreenLocateTexLightedMat.ZIMIdentifyQuadLSD(edge, edgeDir, out Line[] oldLines, out List<Line> lightLines, Screen, conSize, conSize, minLength);
|
|
|
+ var quadLines = ScreenLocateTexLightedMat.ZIMIdentifyQuadLSD(
|
|
|
+ edge, edgeDir,
|
|
|
+ out Line[] oldLines, out List<Line> possibleLines,out List<(Line, float, float)> allLines,
|
|
|
+ Screen, conSize, conSize, minLength);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 将 allLines 输出一张图片
|
|
|
+ var allLinesMap = new Matrix(ScreenLocateTexLightedMat.Size, Tiling: true);
|
|
|
+ foreach (var l in allLines)
|
|
|
+ {
|
|
|
+ if (l.Item1 != null)
|
|
|
+ o0Extension.DrawLine(allLinesMap, l.Item1, (x, y) => 3, new Geometry2D.Float.Vector(0, 2), true);
|
|
|
+ }
|
|
|
+ var allLinesTex = allLinesMap.ToTexRGBA(FloatValueToColor);
|
|
|
+ ScreenLocate.DebugTexture(1, allLinesTex);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// 将识别到的边画出来,并判断能否拼成屏幕,能拼成则设置ScreenMap
|
|
|
// 线段顺序: 下、右、上、左
|
|
|
@@ -706,9 +724,11 @@ namespace o0.Project
|
|
|
quadTemp.Add(screenQuad.Quad);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 还需要输出一张识别结果图,包含干扰线段
|
|
|
var LSDLineMap = new Matrix(ScreenLocateTexLightedMat.Size, Tiling: true);
|
|
|
- foreach (var l in lightLines)
|
|
|
+ foreach (var l in possibleLines)
|
|
|
{
|
|
|
if (l != null && !quadLines.Contains(l))
|
|
|
o0Extension.DrawLine(LSDLineMap, l, (x, y) => 3, new Geometry2D.Float.Vector(0, 2), true); // 其他的备选线段
|
|
|
@@ -725,18 +745,15 @@ namespace o0.Project
|
|
|
}
|
|
|
ChoosableLineTex = LSDLineMap.ToTexRGBA(FloatValueToColor);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 是否将图片保存到本地
|
|
|
if (ScreenLocate.Main.SaveToggle.isOn)
|
|
|
{
|
|
|
- var time = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
|
|
- var FileSavePath = $"{time}屏幕定位数据.bin";
|
|
|
- FileSavePath.FileWriteByte(ScreenWhiteTexture);
|
|
|
-
|
|
|
- var bytes = ScreenLocateTexLighted.EncodeToPNG();
|
|
|
- File.WriteAllBytes($"{time}屏幕.png", bytes);
|
|
|
- bytes = ScreenQuadTex.EncodeToPNG();
|
|
|
- File.WriteAllBytes($"{time}屏幕边框识别.png", bytes);
|
|
|
- Debug.Log("ScreenLocateTexture Saved To: " + FileSavePath);
|
|
|
+ var FileDirectory = $"Debug_屏幕定位图片/";
|
|
|
+ ScreenLocate.Main.StartCoroutine(SaveImagesIEnum(FileDirectory,
|
|
|
+ $"屏幕识别Size: ({Size.x},{Size.y}), 卷积核Size: {conSize}, 最小线段长度: {minLength}",
|
|
|
+ ScreenLocateTex, allLinesTex, ScreenQuadTex));
|
|
|
}
|
|
|
|
|
|
//times.Add(watch.ElapsedMilliseconds);
|
|
|
@@ -755,5 +772,33 @@ namespace o0.Project
|
|
|
UnityEngine.Object.Destroy(ScreenLocateTex);
|
|
|
}
|
|
|
|
|
|
+ IEnumerator SaveImagesIEnum(string FileDirectory, string log, Texture2D ScreenLocateTex, Texture2D allLinesTex, Texture2D ScreenQuadTex)
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(FileDirectory))
|
|
|
+ Directory.CreateDirectory(FileDirectory);
|
|
|
+ var time = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
|
|
+
|
|
|
+ yield return null;
|
|
|
+ var pngData = (ScreenLocate.Main.outputTexture2D[7] as Texture2D)?.EncodeToPNG();
|
|
|
+ if (pngData != null)
|
|
|
+ File.WriteAllBytes($"{FileDirectory}{time}A屏幕原图.png", pngData);
|
|
|
+ yield return null;
|
|
|
+ var pngData1 = ScreenLocateTex.EncodeToPNG();
|
|
|
+ if (pngData1 != null)
|
|
|
+ File.WriteAllBytes($"{FileDirectory}{time}B黑白色差.png", pngData1);
|
|
|
+ yield return null;
|
|
|
+ var pngData2 = allLinesTex.EncodeToPNG();
|
|
|
+ if (pngData2 != null)
|
|
|
+ File.WriteAllBytes($"{FileDirectory}{time}C全部识别线段.png", pngData2);
|
|
|
+ yield return null;
|
|
|
+ var pngData3 = ScreenQuadTex.EncodeToPNG();
|
|
|
+ if (pngData3 != null)
|
|
|
+ File.WriteAllBytes($"{FileDirectory}{time}D识别结果.png", pngData3);
|
|
|
+ yield return null;
|
|
|
+ Debug.Log($"<color=aqua>({time}) 屏幕识别图片保存至:程序根目录/{FileDirectory}</color>");
|
|
|
+ log += $"\r\n屏幕原图保存{pngData != null}, \r\n黑白色差保存{pngData1 != null}, \r\n全部识别线段保存{pngData2 != null}, \r\n识别结果保存{pngData3 != null}, ";
|
|
|
+ File.WriteAllText($"{FileDirectory}{time}_日志.log", log);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|