|
|
@@ -653,14 +653,23 @@ namespace o0.Project
|
|
|
}
|
|
|
else // 获得屏幕差值
|
|
|
{
|
|
|
- PixelsMultipleBatches.Add(ScreenWhiteTexture.Select((i) => new UnityEngine.Color(i.x, i.y, i.z)).ToArray());
|
|
|
+ var maxWhite = 0f;
|
|
|
+ foreach (var i in ScreenWhiteTexture)
|
|
|
+ {
|
|
|
+ var m = i.x > i.y ? (i.x > i.z ? i.x : i.z) : (i.y > i.z ? i.y : i.z);
|
|
|
+ if (maxWhite < m)
|
|
|
+ maxWhite = m;
|
|
|
+ }
|
|
|
+ var scale = 1.0f / maxWhite; // 放大对比度
|
|
|
+
|
|
|
var differPixel = new UnityEngine.Color[Size.x * Size.y];
|
|
|
Parallel.For(0, Size.x * Size.y, i =>
|
|
|
{
|
|
|
var pi = ScreenWhiteTexture[i] - ScreenBlackTexture[i];
|
|
|
- differPixel[i] = new UnityEngine.Color(pi.x, pi.y, pi.z);
|
|
|
+ differPixel[i] = new UnityEngine.Color(pi.x, pi.y, pi.z) * scale;
|
|
|
});
|
|
|
PixelsMultipleBatches.Add(differPixel);
|
|
|
+ PixelsMultipleBatches.Add(ScreenWhiteTexture.Select((i) => new UnityEngine.Color(i.x, i.y, i.z) * scale).ToArray());
|
|
|
}
|
|
|
|
|
|
int conSize = (int)Math.Ceiling(0.007f * Size.y) * 2 + 1;
|
|
|
@@ -672,20 +681,22 @@ namespace o0.Project
|
|
|
|
|
|
var allLines = new List<LineIdentified>();
|
|
|
Texture2D ScreenLocateTexture = null;
|
|
|
+ List<Texture2D> LocateTexTemp = new List<Texture2D>();
|
|
|
List<Matrix> ScreenLocateMatList = new List<Matrix>();
|
|
|
foreach (var batch in PixelsMultipleBatches.Index())
|
|
|
{
|
|
|
- ScreenLocateTexture = ToLocateTex(PixelsMultipleBatches[batch]);
|
|
|
- var ScreenLocateMat = ScreenLocateTexture.Too0Mat(); // 用于获取Lines的Matrix
|
|
|
+ var locateTex = ToLocateTex(PixelsMultipleBatches[batch]);
|
|
|
+ LocateTexTemp.Add(locateTex);
|
|
|
+ var ScreenLocateMat = locateTex.Too0Mat(); // 用于获取Lines的Matrix
|
|
|
var lineCount = ZIMIdentifyQuadLSD(ref allLines, batch, ScreenLocateMat.zimIdentifyEdgeGradientAny(conSize));
|
|
|
log += $"\r\n识别图片{batch}, 识别到的线段数量为: {lineCount}";
|
|
|
ScreenLocateMatList.Add(ScreenLocateMat);
|
|
|
}
|
|
|
+ ScreenLocateTexture = LocateTexTemp[0];
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ var avgPoint = ScreenLocateMatList.Count > 1 ? GetAvgPoint(ScreenLocateMatList[1]) : GetAvgPoint(ScreenLocateMatList[0]);
|
|
|
// 过滤得到四边形的四条边
|
|
|
- var quadLines = FilterLines(ScreenLocateMatList, allLines, GetAvgPoint(ScreenLocateMatList[0]),
|
|
|
+ var quadLines = FilterLines(ScreenLocateMatList, allLines, avgPoint,
|
|
|
out Line[] oldLines, out List<Line> possibleLines,
|
|
|
Screen, conSize, conSize, minLength);
|
|
|
|
|
|
@@ -790,6 +801,11 @@ namespace o0.Project
|
|
|
ScreenLocate.DebugTexture(4, ScreenLocateTexture.Merge(ScreenQuadTex));
|
|
|
ScreenLocate.DebugTexture(5, ChoosableLineTex);
|
|
|
}
|
|
|
+ foreach (var i in LocateTexTemp)
|
|
|
+ {
|
|
|
+ if (i != ScreenLocateTexture) // ScreenLocateTexture 由 ScreenLocate.DebugTexture 释放
|
|
|
+ GameObject.Destroy(i);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Vector GetAvgPoint(Matrix screenLocateMat)
|