|
|
@@ -679,29 +679,22 @@ namespace o0.Project
|
|
|
//sw.Start();
|
|
|
|
|
|
//读取数据
|
|
|
+ int batchCount;
|
|
|
if (debugImages != null && debugImages.Count != 0)
|
|
|
{
|
|
|
+ batchCount = debugImages.Count;
|
|
|
var dSize = debugImages.First().Size();
|
|
|
foreach (var i in debugImages)
|
|
|
{
|
|
|
Debug.Log($"<color=aqua>Debug {i.name}</color>");
|
|
|
if (i.Size() != dSize)
|
|
|
throw new InvalidOperationException("Multiple Debug textures have different sizes");
|
|
|
- PixelsMultipleBatches.Add(i.GetPixels());
|
|
|
+ //PixelsMultipleBatches.Add(i.GetPixels());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else // 获得屏幕差值
|
|
|
{
|
|
|
- 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];
|
|
|
var whitePixel = new UnityEngine.Color[Size.x * Size.y];
|
|
|
Parallel.For(0, Size.x, x =>
|
|
|
@@ -709,28 +702,33 @@ namespace o0.Project
|
|
|
for (int y = 0; y < Size.y; y++)
|
|
|
{
|
|
|
var i = y * Size.x + x;
|
|
|
- var d = ScreenWhiteTexture[i] * scale - ScreenBlackTexture[i];
|
|
|
+ var d = ScreenWhiteTexture[i] - ScreenBlackTexture[i];
|
|
|
differPixel[i] = new UnityEngine.Color(d.x, d.y, d.z);
|
|
|
- whitePixel[i] = new UnityEngine.Color(ScreenWhiteTexture[i].x, ScreenWhiteTexture[i].y, ScreenWhiteTexture[i].z) * scale;
|
|
|
+ whitePixel[i] = new UnityEngine.Color(ScreenWhiteTexture[i].x, ScreenWhiteTexture[i].y, ScreenWhiteTexture[i].z);
|
|
|
}
|
|
|
});
|
|
|
PixelsMultipleBatches.Add(differPixel); // 色差图
|
|
|
PixelsMultipleBatches.Add(whitePixel); // 原图
|
|
|
+ batchCount = PixelsMultipleBatches.Count;
|
|
|
}
|
|
|
|
|
|
int conSize = (int)Math.Ceiling(0.007f * Size.y) * 2 + 1;
|
|
|
conSize = Math.Max(conSize, 7); // 设置最小为7
|
|
|
|
|
|
- float minLength = conSize * 6f;
|
|
|
+ float minLength = conSize * 7.7f;
|
|
|
minLength = locateIndex == -1 ? minLength : minLength * areaPercent; // minLength需要按areaPercent比例缩小
|
|
|
string log = $"[Log][ScreenLocate Auto] Size: ({Size.x},{Size.y}), 卷积核Size: {conSize}, 最小线段长度: {minLength}";
|
|
|
|
|
|
var allLines = new List<LineIdentified>();
|
|
|
List<Texture2D> LocateTexTemp = new List<Texture2D>();
|
|
|
List<Matrix> ScreenLocateMatList = new List<Matrix>();
|
|
|
- foreach (var batch in PixelsMultipleBatches.Index())
|
|
|
+ for (int batch = 0; batch < batchCount; batch++)
|
|
|
{
|
|
|
- var locateTex = ToLocateTex(PixelsMultipleBatches[batch]);
|
|
|
+ Texture2D locateTex;
|
|
|
+ if (debugImages != null && debugImages.Count != 0)
|
|
|
+ locateTex = debugImages[batch];
|
|
|
+ else
|
|
|
+ locateTex = ToLocateTex(PixelsMultipleBatches[batch]);
|
|
|
LocateTexTemp.Add(locateTex);
|
|
|
var ScreenLocateMat = locateTex.Too0Mat(); // 用于获取Lines的Matrix
|
|
|
var lineCount = ZIMIdentifyQuadLSD(
|
|
|
@@ -742,7 +740,7 @@ namespace o0.Project
|
|
|
log += $"\r\n识别图片{batch}, 识别到的线段数量为: {lineCount}";
|
|
|
ScreenLocateMatList.Add(ScreenLocateMat);
|
|
|
}
|
|
|
- Texture2D ScreenLocateTexture = LocateTexTemp[0]; // for output
|
|
|
+ Texture2D ScreenLocateTexture = LocateTexTemp[0]; // 色差图,for output
|
|
|
|
|
|
// LSD计算得到的矩阵尺寸较小(因为卷积),这里必须进行位移
|
|
|
// 新增:根据阈值筛去梯度太低的线段
|
|
|
@@ -1009,7 +1007,7 @@ namespace o0.Project
|
|
|
{
|
|
|
var gM = ScreenGrad(line);
|
|
|
float e = (float)Math.Sqrt(Math.Ceiling(line.Line.Length / minLength)); // 长度系数,筛选时梯度更大、长度更长的线段更优
|
|
|
- float d = (5 - distanceRatio) / 4; // 距离系数,距离越近,系数越大
|
|
|
+ float d = (1.3f - distanceRatio) / 0.3f; // 距离系数,距离越近,系数越大
|
|
|
|
|
|
line.ZIMGradient = e * d * gM; // 记录一下综合梯度,全自动新增的功能会二次使用
|
|
|
return line.ZIMGradient;
|
|
|
@@ -1124,7 +1122,7 @@ namespace o0.Project
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- var (interA, interB) = FindInterLinePair(new LineGuess(screenLocateMatList, gradientLength * 2, minLength), interSelectable, 12);
|
|
|
+ var (interA, interB) = FindInterLinePair(new LineGuess(screenLocateMatList, gradientLength * 2, minLength), interSelectable, 8);
|
|
|
if (interA != null) // 替换上一步筛选的结果中的部分边,得到最终的结果
|
|
|
resultAuto[interA.ScreenLineIndex] = interA;
|
|
|
if (interB != null)
|
|
|
@@ -1143,7 +1141,8 @@ namespace o0.Project
|
|
|
{
|
|
|
if (lineGuess.GuessIsLine(line)) // 评价是不是Line, 并且找到离中心点最近的
|
|
|
{
|
|
|
- Debug.Log("[ScreenIdentification] guess is line: (index)" + line.ScreenLineIndex);
|
|
|
+ if (ScreenLocate.Main.DebugOnZIMDemo)
|
|
|
+ Debug.Log($"[ScreenIdentification] {interSelectable.IndexOf(line)}, guess is line: (index)" + line.ScreenLineIndex);
|
|
|
if (selected[line.ScreenLineIndex] == null || selected[line.ScreenLineIndex].DistanceToMiddle > line.DistanceToMiddle)
|
|
|
selected[line.ScreenLineIndex] = line;
|
|
|
}
|